Ejemplo n.º 1
0
    def create_widgets_on_tk(self):
        x, y = 150, 80

        self.label_1 = customtkinter.CTkLabel(master=self,
                                              text="widgets_on_tk",
                                              fg_color="gray50")
        self.label_1.place(x=x, y=y, anchor=tkinter.CENTER)

        self.frame_1 = customtkinter.CTkFrame(master=self,
                                              width=200,
                                              height=60)
        self.frame_1.place(x=x, y=y + 80, anchor=tkinter.CENTER)

        self.button_1 = customtkinter.CTkButton(master=self)
        self.button_1.place(x=x, y=y + 160, anchor=tkinter.CENTER)

        self.entry_1 = customtkinter.CTkEntry(master=self)
        self.entry_1.place(x=x, y=y + 240, anchor=tkinter.CENTER)

        self.progress_bar_1 = customtkinter.CTkProgressBar(master=self)
        self.progress_bar_1.place(x=x, y=y + 320, anchor=tkinter.CENTER)

        self.slider_1 = customtkinter.CTkSlider(
            master=self,
            command=self.change_appearance_mode,
            from_=0,
            to=2,
            number_of_steps=2)
        self.slider_1.place(x=x, y=y + 400, anchor=tkinter.CENTER)

        self.check_box_1 = customtkinter.CTkCheckBox(master=self)
        self.check_box_1.place(x=x, y=y + 480, anchor=tkinter.CENTER)
Ejemplo n.º 2
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.title(App.APP_NAME)
        self.geometry(str(App.WIDTH) + "x" + str(App.HEIGHT))
        self.minsize(App.WIDTH, App.HEIGHT)

        self.protocol("WM_DELETE_WINDOW", self.on_closing)
        # ============ create two CTkFrames ============

        self.frame_left = customtkinter.CTkFrame(master=self,
                                                width=220,
                                                height=App.HEIGHT-40,
                                                corner_radius=5)
        self.frame_left.place(relx=0.38, rely=0.5, anchor=tkinter.E)

        self.frame_right = customtkinter.CTkFrame(master=self,
                                                width=350,
                                                height=App.HEIGHT-40,
                                                corner_radius=5)
        self.frame_right.place(relx=0.40, rely=0.5, anchor=tkinter.W)

#        # ============ frame_right ============

        self.button_output = customtkinter.CTkButton(master=self.frame_right, border_color=App.MAIN_COLOR,
                                                fg_color=None, hover_color=App.MAIN_HOVER,
                                                height=28, text="Output Folder", command=self.button_outputFunc,
                                                border_width=3, corner_radius=10, text_font=('Calibri',12))
        self.button_output.place(relx=0.05, rely=0.06, anchor=tkinter.NW)
        self.entry_output = customtkinter.CTkEntry(master=self.frame_right, width=320, height=38, corner_radius=5)
        self.entry_output.place(relx=0.05, rely=0.18, anchor=tkinter.NW)
Ejemplo n.º 3
0
    def create_widgets_on_tk_frame_customized(self):
        x, y = 1150, 40

        self.tk_frame_customized = tkinter.Frame(master=self,
                                                 width=300,
                                                 height=600,
                                                 bg="darkred")
        self.tk_frame_customized.place(x=x, y=y, anchor=tkinter.N)

        self.label_4 = customtkinter.CTkLabel(master=self.tk_frame_customized,
                                              text="customized",
                                              corner_radius=6)
        self.label_4.place(relx=0.5, y=y, anchor=tkinter.CENTER)
        self.label_4.configure(fg_color=("#F4F4FA", "#333D5E"),
                               text_color=("#373E57", "#7992C1"))

        self.frame_4 = customtkinter.CTkFrame(master=self.tk_frame_customized,
                                              width=200,
                                              height=60)
        self.frame_4.place(relx=0.5, y=y + 80, anchor=tkinter.CENTER)
        self.frame_4.configure(fg_color=("#EBECF3", "#4B577E"))

        self.button_4 = customtkinter.CTkButton(
            master=self.tk_frame_customized, command=lambda: x, border_width=3)
        self.button_4.place(relx=0.5, y=y + 160, anchor=tkinter.CENTER)
        self.button_4.configure(border_color=("#4F90F8", "#6FADF9"),
                                hover_color=("#3A65E8", "#4376EE"))
        self.button_4.configure(fg_color=None)

        self.entry_4 = customtkinter.CTkEntry(master=self.tk_frame_customized)
        self.entry_4.place(relx=0.5, y=y + 240, anchor=tkinter.CENTER)
        self.entry_4.configure(fg_color=("gray60", "gray5"))
        self.entry_4.insert(0, "1234567890")
        self.entry_4.focus_set()

        self.progress_bar_4 = customtkinter.CTkProgressBar(
            master=self.tk_frame_customized,
            height=16,
            fg_color=("#EBECF3", "#4B577E"))
        self.progress_bar_4.place(relx=0.5, y=y + 320, anchor=tkinter.CENTER)
        self.progress_bar_4.configure(progress_color="#8AE0C3",
                                      border_width=3,
                                      border_color=("gray60", "#4B577E"))

        self.slider_4 = customtkinter.CTkSlider(
            master=self.tk_frame_customized,
            command=self.change_frame_color,
            from_=0,
            to=10)
        self.slider_4.place(relx=0.5, y=y + 400, anchor=tkinter.CENTER)
        self.slider_4.configure(button_color="#8AE0C3",
                                fg_color=("#EBECF3", "#4B577E"),
                                progress_color=("gray30", "gray10"))
        self.slider_4.configure(from_=0, to=1)

        self.check_box_4 = customtkinter.CTkCheckBox(
            master=self.tk_frame_customized)
        self.check_box_4.place(relx=0.5, y=y + 480, anchor=tkinter.CENTER)
        self.check_box_4.configure(border_color="#8AE0C3")
Ejemplo n.º 4
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.geometry("500x400")

        self.button_1 = customtkinter.CTkButton(self,
                                                text="Create CTkToplevel",
                                                command=self.create_toplevel)
        self.button_1.pack(side="top", padx=40, pady=40)
Ejemplo n.º 5
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.title(App.APP_NAME)
        self.geometry(f"{App.WIDTH}x{App.HEIGHT}")
        self.minsize(App.WIDTH, App.HEIGHT)
        self.maxsize(App.WIDTH, App.HEIGHT)
        self.resizable(False, False)

        self.protocol("WM_DELETE_WINDOW", self.on_closing)

        # load image with PIL and convert to PhotoImage
        image = Image.open(PATH + "/test_images/bg_gradient.jpg").resize(
            (self.WIDTH, self.HEIGHT))
        self.bg_image = ImageTk.PhotoImage(image)

        self.image_label = tkinter.Label(master=self, image=self.bg_image)
        self.image_label.place(relx=0.5, rely=0.5, anchor=tkinter.CENTER)

        self.frame = customtkinter.CTkFrame(master=self,
                                            width=300,
                                            height=App.HEIGHT,
                                            corner_radius=0)
        self.frame.place(relx=0.5, rely=0.5, anchor=tkinter.CENTER)

        self.label_1 = customtkinter.CTkLabel(
            master=self.frame,
            width=200,
            height=60,
            fg_color=("gray70", "gray25"),
            text="CustomTkinter\ninterface example")
        self.label_1.place(relx=0.5, rely=0.3, anchor=tkinter.CENTER)

        self.entry_1 = customtkinter.CTkEntry(master=self.frame,
                                              corner_radius=6,
                                              width=200,
                                              placeholder_text="username")
        self.entry_1.place(relx=0.5, rely=0.52, anchor=tkinter.CENTER)

        self.entry_2 = customtkinter.CTkEntry(master=self.frame,
                                              corner_radius=6,
                                              width=200,
                                              show="*",
                                              placeholder_text="password")
        self.entry_2.place(relx=0.5, rely=0.6, anchor=tkinter.CENTER)

        self.button_2 = customtkinter.CTkButton(master=self.frame,
                                                text="Login",
                                                corner_radius=6,
                                                command=self.button_event,
                                                width=200)
        self.button_2.place(relx=0.5, rely=0.7, anchor=tkinter.CENTER)
    def __init__(self, master, x, y, options):
        super().__init__()

        self.overrideredirect(True)
        self.geometry(f"120x{len(options) * (25 + 3) + 3}+{x}+{y}")

        if sys.platform.startswith("darwin"):
            self.overrideredirect(False)
            self.wm_attributes("-transparent", True)  # turn off shadow
            self.config(bg='systemTransparent')  # transparent bg
            self.frame = customtkinter.CTkFrame(self, border_width=0, width=120, corner_radius=6, border_color="gray4", fg_color="#333740")
        elif sys.platform.startswith("win"):
            self.configure(bg="#FFFFF1")
            self.wm_attributes("-transparent", "#FFFFF1")
            self.focus()
            self.frame = customtkinter.CTkFrame(self, border_width=0, width=120, corner_radius=6, border_color="gray4", fg_color="#333740",
                                                overwrite_preferred_drawing_method="circle_shapes")
        else:
            self.configure(bg="#FFFFF1")
            self.wm_attributes("-transparent", "#FFFFF1")
            self.frame = customtkinter.CTkFrame(self, border_width=0, width=120, corner_radius=6, border_color="gray4", fg_color="#333740",
                                                overwrite_preferred_drawing_method="circle_shapes")

        self.frame.grid(row=0, column=0, sticky="nsew", rowspan=len(options) + 1, columnspan=1, ipadx=0, ipady=0)

        self.frame.grid_rowconfigure(len(options) + 1, minsize=3)
        self.frame.grid_columnconfigure(0, weight=1)
        self.grid_columnconfigure(0, weight=1)

        self.buttons = []
        for index, option in enumerate(options):
            button = customtkinter.CTkButton(self.frame, text=option, height=25, width=108, fg_color="#333740", text_color="gray74",
                                             hover_color="gray28", corner_radius=4, command=self.button_click)
            button.text_label.grid(row=0, column=0, rowspan=2, columnspan=2, sticky="w")
            button.grid(row=index, column=0, padx=(3, 3), pady=(3, 0), columnspan=1, rowspan=1, sticky="ew")
            self.buttons.append(button)

        self.bind("<FocusOut>", self.focus_loss_event)
        self.frame.canvas.bind("<Button-1>", self.focus_loss_event)
Ejemplo n.º 7
0
    def create_widgets_on_ctk_frame(self):
        x, y = 450, 40

        self.ctk_frame = customtkinter.CTkFrame(master=self,
                                                width=300,
                                                height=600)
        self.ctk_frame.place(x=x, y=y, anchor=tkinter.N)

        self.label_2 = customtkinter.CTkLabel(
            master=self.ctk_frame,
            text="create_widgets_on_ctk_frame",
            fg_color="gray50",
            width=200)
        self.label_2.place(relx=0.5, y=y, anchor=tkinter.CENTER)

        self.frame_2 = customtkinter.CTkFrame(master=self.ctk_frame,
                                              width=200,
                                              height=60)
        self.frame_2.place(relx=0.5, y=y + 80, anchor=tkinter.CENTER)

        self.button_2 = customtkinter.CTkButton(master=self.ctk_frame,
                                                border_width=3)
        self.button_2.place(relx=0.5, y=y + 160, anchor=tkinter.CENTER)

        self.entry_2 = customtkinter.CTkEntry(master=self.ctk_frame)
        self.entry_2.place(relx=0.5, y=y + 240, anchor=tkinter.CENTER)

        self.progress_bar_2 = customtkinter.CTkProgressBar(
            master=self.ctk_frame)
        self.progress_bar_2.place(relx=0.5, y=y + 320, anchor=tkinter.CENTER)

        self.slider_2 = customtkinter.CTkSlider(
            master=self.ctk_frame,
            command=lambda v: self.label_2.set_text(str(round(v, 5))))
        self.slider_2.place(relx=0.5, y=y + 400, anchor=tkinter.CENTER)

        self.check_box_2 = customtkinter.CTkCheckBox(master=self.ctk_frame)
        self.check_box_2.place(relx=0.5, y=y + 480, anchor=tkinter.CENTER)
            self.buttons.append(button)

        self.bind("<FocusOut>", self.focus_loss_event)
        self.frame.canvas.bind("<Button-1>", self.focus_loss_event)

    def focus_loss_event(self, event):
        print("focus loss")
        self.destroy()
        # self.update()

    def button_click(self):
        print("button press")
        self.destroy()
        # self.update()


app = customtkinter.CTk()
app.geometry("600x500")


def open_menu():
    menu = CTkMenu(app, button.winfo_rootx(), button.winfo_rooty() + button.winfo_height() + 4, ["Option 1", "Option 2", "Point 3"])

button = customtkinter.CTkButton(command=open_menu, height=30, corner_radius=6)
button.pack(pady=20)

button_2 = customtkinter.CTkButton(command=open_menu, height=30, corner_radius=6)
button_2.pack(pady=60)

app.mainloop()
app.title("CustomTkinter Test")


def change_state(widget):
    if widget.state == tkinter.NORMAL:
        widget.configure(state=tkinter.DISABLED)
    elif widget.state == tkinter.DISABLED:
        widget.configure(state=tkinter.NORMAL)


def widget_click():
    print("widget clicked")


button_1 = customtkinter.CTkButton(master=app,
                                   text="button_1",
                                   command=widget_click)
button_1.pack(padx=20, pady=(20, 10))
button_2 = customtkinter.CTkButton(master=app,
                                   text="Disable/Enable button_1",
                                   command=lambda: change_state(button_1))
button_2.pack(padx=20, pady=(10, 20))

switch_1 = customtkinter.CTkSwitch(master=app,
                                   text="switch_1",
                                   command=widget_click)
switch_1.pack(padx=20, pady=(20, 10))
button_2 = customtkinter.CTkButton(master=app,
                                   text="Disable/Enable switch_1",
                                   command=lambda: change_state(switch_1))
button_2.pack(padx=20, pady=(10, 20))
f2.grid(row=0, column=1, rowspan=1, columnspan=1, sticky="nsew")
f2.grid_columnconfigure(0, weight=1)

f3 = customtkinter.CTkFrame(app, fg_color="gray85", corner_radius=0)
f3.grid(row=0, column=2, rowspan=1, columnspan=1, sticky="nsew")
f3.grid_columnconfigure(0, weight=1)

f4 = customtkinter.CTkFrame(app, fg_color="gray90", corner_radius=0)
f4.grid(row=0, column=3, rowspan=1, columnspan=1, sticky="nsew")
f4.grid_columnconfigure(0, weight=1)

for i in range(0, 21, 1):
    b = customtkinter.CTkButton(f1,
                                corner_radius=i,
                                height=34,
                                border_width=2,
                                text=f"{i} {i-2}",
                                border_color="white",
                                fg_color=None,
                                text_color="white")
    # b = tkinter.Button(f1,  text=f"{i} {i-2}", width=20)
    b.grid(row=i, column=0, pady=5, padx=15, sticky="nsew")

    b = customtkinter.CTkButton(f2,
                                corner_radius=i,
                                height=34,
                                border_width=0,
                                text=f"{i}",
                                fg_color="#228da8")
    b.grid(row=i, column=0, pady=5, padx=15, sticky="nsew")

    b = customtkinter.CTkButton(f3,
Ejemplo n.º 11
0
 def __init__(self):
     self.root_ctk = customtkinter.CTk()
     self.ctk_button = customtkinter.CTkButton(self.root_ctk)
     self.ctk_button.pack(padx=20, pady=20)
     self.root_ctk.title(self.__class__.__name__)
Ejemplo n.º 12
0
    def __init__(self,
                 *args,
                 fg_color="#555555",
                 button_color="gray50",
                 button_hover_color="gray35",
                 text_color="black",
                 corner_radius=6,
                 button_corner_radius=3,
                 width=120,
                 button_height=24,
                 x_position=0,
                 y_position=0,
                 x_spacing=3,
                 y_spacing=3,
                 command=None,
                 values=None,
                 **kwargs):
        super().__init__(*args, **kwargs)

        ScalingTracker.add_widget(self.set_scaling, self)
        self._widget_scaling = ScalingTracker.get_widget_scaling(self)
        self._spacing_scaling = ScalingTracker.get_spacing_scaling(self)

        self.values = values
        self.command = command

        # color
        self.appearance_mode = AppearanceModeTracker.get_mode(
        )  # 0: "Light" 1: "Dark"
        self.fg_color = fg_color
        self.button_color = button_color
        self.button_hover_color = button_hover_color
        self.text_color = text_color

        # shape
        self.corner_radius = corner_radius
        self.button_corner_radius = button_corner_radius
        self.button_height = button_height
        self.width = width
        self.height = max(len(self.values), 1) * (
            self.button_height + self.apply_spacing_scaling(y_spacing)
        ) + self.apply_spacing_scaling(y_spacing)

        self.geometry(f"{round(self.apply_widget_scaling(self.width))}x" +
                      f"{round(self.apply_widget_scaling(self.height))}+" +
                      f"{round(x_position)}+{round(y_position)}")
        self.grid_columnconfigure(0, weight=1)
        self.grid_rowconfigure(0, weight=1)

        if sys.platform.startswith("darwin"):
            self.overrideredirect(True)  # remove title-bar
            self.overrideredirect(False)
            self.wm_attributes("-transparent", True)  # turn off window shadow
            self.config(bg='systemTransparent')  # transparent bg
            self.frame = customtkinter.CTkFrame(
                self,
                border_width=0,
                width=self.width,
                corner_radius=self.corner_radius,
                fg_color=ThemeManager.single_color(self.fg_color,
                                                   self.appearance_mode))

        elif sys.platform.startswith("win"):
            self.overrideredirect(True)  # remove title-bar
            self.configure(bg="#010302")
            self.wm_attributes("-transparentcolor", "#010302")
            self.focus()
            self.frame = customtkinter.CTkFrame(
                self,
                border_width=0,
                width=self.width,
                corner_radius=self.corner_radius,
                fg_color=self.fg_color,
                overwrite_preferred_drawing_method="circle_shapes")
        else:
            self.overrideredirect(True)  # remove title-bar
            self.configure(bg="#010302")
            self.wm_attributes("-transparentcolor", "#010302")
            self.frame = customtkinter.CTkFrame(
                self,
                border_width=0,
                width=self.width,
                corner_radius=self.corner_radius,
                fg_color=self.fg_color,
                overwrite_preferred_drawing_method="circle_shapes")

        self.frame.grid(row=0, column=0, sticky="nsew", rowspan=1)
        self.frame.grid_rowconfigure(
            len(self.values) + 1,
            minsize=self.apply_spacing_scaling(
                y_spacing))  # add spacing at the bottom
        self.frame.grid_columnconfigure(0, weight=1)

        self.button_list = []
        for index, option in enumerate(self.values):
            button = customtkinter.CTkButton(
                self.frame,
                text=option,
                height=self.button_height,
                width=self.width - 2 * self.apply_widget_scaling(x_spacing),
                fg_color=self.button_color,
                text_color=self.text_color,
                hover_color=self.button_hover_color,
                corner_radius=self.button_corner_radius,
                command=lambda i=index: self.button_callback(i))
            button.text_label.configure(anchor="w")
            button.text_label.grid(row=0,
                                   column=0,
                                   rowspan=2,
                                   columnspan=2,
                                   sticky="w")
            button.grid(row=index,
                        column=0,
                        padx=self.apply_widget_scaling(x_spacing),
                        pady=(self.apply_widget_scaling(y_spacing), 0),
                        sticky="ew")
            self.button_list.append(button)

        self.bind("<FocusOut>", self.focus_loss_event)
        self.frame.canvas.bind("<Button-1>", self.focus_loss_event)
Ejemplo n.º 13
0
app.grid_columnconfigure(0, weight=1, minsize=200)

frame_1 = customtkinter.CTkFrame(master=app,
                                 width=250,
                                 height=240,
                                 corner_radius=15)
frame_1.grid(row=0, column=0, padx=20, pady=20, sticky="nsew")

frame_1.grid_columnconfigure(0, weight=1)
frame_1.grid_columnconfigure(1, weight=1)
frame_1.grid_rowconfigure(0, minsize=10)  # add empty row for spacing

button_1 = customtkinter.CTkButton(master=frame_1,
                                   image=add_folder_image,
                                   text="Add Folder",
                                   width=190,
                                   height=40,
                                   compound="right",
                                   command=button_function)
button_1.grid(row=1, column=0, columnspan=2, padx=20, pady=10, sticky="ew")

button_2 = customtkinter.CTkButton(master=frame_1,
                                   image=add_list_image,
                                   text="Add Item",
                                   width=190,
                                   height=40,
                                   compound="right",
                                   fg_color="#D35B58",
                                   hover_color="#C77C78",
                                   command=button_function)
button_2.grid(row=2, column=0, columnspan=2, padx=20, pady=10, sticky="ew")
app.geometry("400x800")
app.title("Tkinter Variable Test")

txt_var = tkinter.StringVar(value="")
entry_1 = customtkinter.CTkEntry(app, width=200, textvariable=txt_var)
entry_1.pack(pady=15)
txt_var.set("new text test")
if TEST_CONFIGURE: entry_1.configure(textvariable=txt_var)
if TEST_REMOVING: entry_1.configure(textvariable="")

label_1 = customtkinter.CTkLabel(app, width=200, textvariable=txt_var)
label_1.pack(pady=15)
if TEST_CONFIGURE: label_1.configure(textvariable=txt_var)
if TEST_REMOVING: label_1.configure(textvariable="")

button_1 = customtkinter.CTkButton(app, width=200, textvariable=txt_var)
button_1.pack(pady=15)
int_var = tkinter.IntVar(value=10)
if TEST_CONFIGURE: button_1.configure(textvariable=int_var)
if TEST_REMOVING: button_1.configure(textvariable="")

slider_1 = customtkinter.CTkSlider(app,
                                   width=200,
                                   from_=0,
                                   to=3,
                                   variable=int_var)
slider_1.pack(pady=15)
if TEST_CONFIGURE: slider_1.configure(variable=int_var)
if TEST_REMOVING: slider_1.configure(variable="")
int_var.set(2)
Ejemplo n.º 15
0
    def __init__(self):
        super().__init__()

        self.title("CustomTkinter complex_example.py")
        self.geometry(f"{App.WIDTH}x{App.HEIGHT}")
        self.protocol(
            "WM_DELETE_WINDOW",
            self.on_closing)  # call .on_closing() when app gets closed

        # ============ create two frames ============

        # configure grid layout (2x1)
        self.grid_columnconfigure(1, weight=1)
        self.grid_rowconfigure(0, weight=1)

        self.frame_left = customtkinter.CTkFrame(master=self,
                                                 width=180,
                                                 corner_radius=0)
        self.frame_left.grid(row=0, column=0, sticky="nswe")

        self.frame_right = customtkinter.CTkFrame(master=self)
        self.frame_right.grid(row=0, column=1, sticky="nswe", padx=20, pady=20)

        # ============ frame_left ============

        # configure grid layout (1x11)
        self.frame_left.grid_rowconfigure(
            0, minsize=10)  # empty row with minsize as spacing
        self.frame_left.grid_rowconfigure(5, weight=1)  # empty row as spacing
        self.frame_left.grid_rowconfigure(
            8, minsize=20)  # empty row with minsize as spacing
        self.frame_left.grid_rowconfigure(
            11, minsize=10)  # empty row with minsize as spacing

        self.label_1 = customtkinter.CTkLabel(
            master=self.frame_left,
            text="CustomTkinter",
            text_font=("Roboto Medium", -16))  # font name and size in px
        self.label_1.grid(row=1, column=0, pady=10, padx=10)

        self.button_1 = customtkinter.CTkButton(
            master=self.frame_left,
            text="CTkButton 1",
            fg_color=("gray75", "gray30"),  # <- custom tuple-color
            command=self.button_event)
        self.button_1.grid(row=2, column=0, pady=10, padx=20)

        self.button_2 = customtkinter.CTkButton(
            master=self.frame_left,
            text="CTkButton 2",
            fg_color=("gray75", "gray30"),  # <- custom tuple-color
            command=self.button_event)
        self.button_2.grid(row=3, column=0, pady=10, padx=20)

        self.button_3 = customtkinter.CTkButton(
            master=self.frame_left,
            text="CTkButton 3",
            fg_color=("gray75", "gray30"),  # <- custom tuple-color
            command=self.button_event)
        self.button_3.grid(row=4, column=0, pady=10, padx=20)

        self.switch_1 = customtkinter.CTkSwitch(master=self.frame_left)
        self.switch_1.grid(row=9, column=0, pady=10, padx=20, sticky="w")

        self.switch_2 = customtkinter.CTkSwitch(master=self.frame_left,
                                                text="Dark Mode",
                                                command=self.change_mode)
        self.switch_2.grid(row=10, column=0, pady=10, padx=20, sticky="w")

        # ============ frame_right ============

        # configure grid layout (3x7)
        self.frame_right.rowconfigure((0, 1, 2, 3), weight=1)
        self.frame_right.rowconfigure(7, weight=10)
        self.frame_right.columnconfigure((0, 1), weight=1)
        self.frame_right.columnconfigure(2, weight=0)

        self.frame_info = customtkinter.CTkFrame(master=self.frame_right)
        self.frame_info.grid(row=0,
                             column=0,
                             columnspan=2,
                             rowspan=4,
                             pady=20,
                             padx=20,
                             sticky="nsew")

        # ============ frame_info ============

        # configure grid layout (1x1)
        self.frame_info.rowconfigure(0, weight=1)
        self.frame_info.columnconfigure(0, weight=1)

        self.label_info_1 = customtkinter.CTkLabel(
            master=self.frame_info,
            text="CTkLabel: Lorem ipsum dolor sit,\n" +
            "amet consetetur sadipscing elitr,\n" +
            "sed diam nonumy eirmod tempor",
            height=100,
            fg_color=("white", "gray38"),  # <- custom tuple-color
            justify=tkinter.LEFT)
        self.label_info_1.grid(column=0, row=0, sticky="nwe", padx=15, pady=15)

        self.progressbar = customtkinter.CTkProgressBar(master=self.frame_info)
        self.progressbar.grid(row=1, column=0, sticky="ew", padx=15, pady=15)

        # ============ frame_right ============

        self.radio_var = tkinter.IntVar(value=0)

        self.label_radio_group = customtkinter.CTkLabel(
            master=self.frame_right, text="CTkRadioButton Group:")
        self.label_radio_group.grid(row=0,
                                    column=2,
                                    columnspan=1,
                                    pady=20,
                                    padx=10,
                                    sticky="")

        self.radio_button_1 = customtkinter.CTkRadioButton(
            master=self.frame_right, variable=self.radio_var, value=0)
        self.radio_button_1.grid(row=1, column=2, pady=10, padx=20, sticky="n")

        self.radio_button_2 = customtkinter.CTkRadioButton(
            master=self.frame_right, variable=self.radio_var, value=1)
        self.radio_button_2.grid(row=2, column=2, pady=10, padx=20, sticky="n")

        self.radio_button_3 = customtkinter.CTkRadioButton(
            master=self.frame_right, variable=self.radio_var, value=2)
        self.radio_button_3.grid(row=3, column=2, pady=10, padx=20, sticky="n")

        self.slider_1 = customtkinter.CTkSlider(master=self.frame_right,
                                                from_=0,
                                                to=1,
                                                number_of_steps=3,
                                                command=self.progressbar.set)
        self.slider_1.grid(row=4,
                           column=0,
                           columnspan=2,
                           pady=10,
                           padx=20,
                           sticky="we")

        self.slider_2 = customtkinter.CTkSlider(master=self.frame_right,
                                                command=self.progressbar.set)
        self.slider_2.grid(row=5,
                           column=0,
                           columnspan=2,
                           pady=10,
                           padx=20,
                           sticky="we")

        self.slider_button_1 = customtkinter.CTkButton(
            master=self.frame_right,
            height=25,
            text="CTkButton",
            command=self.button_event)
        self.slider_button_1.grid(row=4,
                                  column=2,
                                  columnspan=1,
                                  pady=10,
                                  padx=20,
                                  sticky="we")

        self.slider_button_2 = customtkinter.CTkButton(
            master=self.frame_right,
            height=25,
            text="CTkButton",
            command=self.button_event)
        self.slider_button_2.grid(row=5,
                                  column=2,
                                  columnspan=1,
                                  pady=10,
                                  padx=20,
                                  sticky="we")

        self.checkbox_button_1 = customtkinter.CTkButton(
            master=self.frame_right,
            height=25,
            text="CTkButton",
            border_width=3,  # <- custom border_width
            fg_color=None,  # <- no fg_color
            command=self.button_event)
        self.checkbox_button_1.grid(row=6,
                                    column=2,
                                    columnspan=1,
                                    pady=10,
                                    padx=20,
                                    sticky="we")

        self.check_box_1 = customtkinter.CTkCheckBox(master=self.frame_right,
                                                     text="CTkCheckBox")
        self.check_box_1.grid(row=6, column=0, pady=10, padx=20, sticky="w")

        self.check_box_2 = customtkinter.CTkCheckBox(master=self.frame_right,
                                                     text="CTkCheckBox")
        self.check_box_2.grid(row=6, column=1, pady=10, padx=20, sticky="w")

        self.entry = customtkinter.CTkEntry(master=self.frame_right,
                                            width=120,
                                            placeholder_text="CTkEntry")
        self.entry.grid(row=8,
                        column=0,
                        columnspan=2,
                        pady=20,
                        padx=20,
                        sticky="we")

        self.button_5 = customtkinter.CTkButton(master=self.frame_right,
                                                text="CTkButton",
                                                command=self.button_event)
        self.button_5.grid(row=8,
                           column=2,
                           columnspan=1,
                           pady=20,
                           padx=20,
                           sticky="we")

        # set default values
        self.radio_button_1.select()
        self.switch_2.select()
        self.slider_1.set(0.2)
        self.slider_2.set(0.7)
        self.progressbar.set(0.5)
        self.slider_button_1.configure(state=tkinter.DISABLED,
                                       text="Disabled Button")
        self.radio_button_3.configure(state=tkinter.DISABLED)
        self.check_box_1.configure(state=tkinter.DISABLED,
                                   text="CheckBox disabled")
        self.check_box_2.select()
    customtkinter.set_widget_scaling(value * 2)
    customtkinter.set_spacing_scaling(value * 2)
    customtkinter.set_window_scaling(value * 2)
    progressbar_1.set(value)


y_padding = 13

frame_1 = customtkinter.CTkFrame(master=app)
frame_1.pack(pady=20, padx=60, fill="both", expand=True)
label_1 = customtkinter.CTkLabel(master=frame_1, justify=tkinter.LEFT)
label_1.pack(pady=y_padding, padx=10)
progressbar_1 = customtkinter.CTkProgressBar(master=frame_1)
progressbar_1.pack(pady=y_padding, padx=10)
button_1 = customtkinter.CTkButton(master=frame_1,
                                   corner_radius=8,
                                   command=button_function)
button_1.pack(pady=y_padding, padx=10)
slider_1 = customtkinter.CTkSlider(master=frame_1,
                                   command=slider_function,
                                   from_=0,
                                   to=1)
slider_1.pack(pady=y_padding, padx=10)
slider_1.set(0.5)
entry_1 = customtkinter.CTkEntry(master=frame_1, placeholder_text="CTkEntry")
entry_1.pack(pady=y_padding, padx=10)
checkbox_1 = customtkinter.CTkCheckBox(master=frame_1)
checkbox_1.pack(pady=y_padding, padx=10)
radiobutton_var = tkinter.IntVar(value=1)
radiobutton_1 = customtkinter.CTkRadioButton(master=frame_1,
                                             variable=radiobutton_var,
Ejemplo n.º 17
0
import customtkinter

customtkinter.set_appearance_mode("dark")
customtkinter.set_default_color_theme("blue")

app = customtkinter.CTk()
app.geometry("400x300")
app.title("CTkDialog Test")


def change_mode():
    if c1.get() == 0:
        customtkinter.set_appearance_mode("light")
    else:
        customtkinter.set_appearance_mode("dark")


def button_click_event():
    dialog = customtkinter.CTkInputDialog(master=None, text="Type in a number:", title="Test")
    print("Number:", dialog.get_input())


button = customtkinter.CTkButton(app, text="Open Dialog", command=button_click_event)
button.place(relx=0.5, rely=0.5, anchor=customtkinter.CENTER)
c1 = customtkinter.CTkCheckBox(app, text="dark mode", command=change_mode)
c1.place(relx=0.5, rely=0.8, anchor=customtkinter.CENTER)

app.mainloop()
Ejemplo n.º 18
0

def slider_callback(value):
    progressbar_1.set(value)


frame_1 = customtkinter.CTkFrame(master=app)
frame_1.pack(pady=20, padx=60, fill="both", expand=True)

label_1 = customtkinter.CTkLabel(master=frame_1, justify=tkinter.LEFT)
label_1.pack(pady=12, padx=10)

progressbar_1 = customtkinter.CTkProgressBar(master=frame_1)
progressbar_1.pack(pady=12, padx=10)

button_1 = customtkinter.CTkButton(master=frame_1, command=button_callback)
button_1.pack(pady=12, padx=10)

slider_1 = customtkinter.CTkSlider(master=frame_1,
                                   command=slider_callback,
                                   from_=0,
                                   to=1)
slider_1.pack(pady=12, padx=10)
slider_1.set(0.5)

entry_1 = customtkinter.CTkEntry(master=frame_1, placeholder_text="CTkEntry")
entry_1.pack(pady=12, padx=10)

optionmenu_1 = customtkinter.CTkOptionMenu(
    frame_1, values=["Option 1", "Option 2", "Option 42"])
optionmenu_1.pack(pady=12, padx=10)

app = customtkinter.CTk()
app.geometry("400x400")


def button_callback():
    button_1.configure(width=random.randint(30, 200), height=random.randint(30, 60))
    frame_1.configure(width=random.randint(30, 200), height=random.randint(30, 200))
    label_1.configure(width=random.randint(30, 200), height=random.randint(30, 40))
    entry_1.configure(width=random.randint(30, 200), height=random.randint(30, 40))
    progressbar_1.configure(width=random.randint(30, 200), height=random.randint(10, 16))
    slider_1.configure(width=random.randint(30, 200), height=random.randint(14, 20))


button_1 = customtkinter.CTkButton(app, text="button_1", command=button_callback)
button_1.pack(pady=10)

frame_1 = customtkinter.CTkFrame(app)
frame_1.pack(pady=10)

label_1 = customtkinter.CTkLabel(app, fg_color="green")
label_1.pack(pady=10)

entry_1 = customtkinter.CTkEntry(app, placeholder_text="placeholder")
entry_1.pack(pady=10)

progressbar_1 = customtkinter.CTkProgressBar(app)
progressbar_1.pack(pady=10)

slider_1 = customtkinter.CTkSlider(app)
Ejemplo n.º 20
0
import customtkinter

app = customtkinter.CTk()
app.geometry("400x240")


def button_function():

    top = customtkinter.CTkToplevel(app)

    app.after(1000, top.iconify)  # hide toplevel
    app.after(1500, top.deiconify)  # show toplevel
    app.after(2500, app.iconify)  # hide app
    app.after(3000, app.deiconify)  # show app
    app.after(4000, app.destroy)  # destroy everything


button = customtkinter.CTkButton(app, command=button_function)
button.pack(pady=20, padx=20)

app.mainloop()
Ejemplo n.º 21
0
import tkinter
import tkinter.ttk as ttk
import customtkinter

customtkinter.set_appearance_mode("light")

app = customtkinter.CTk()
app.geometry("1400x480")
app.title("CustomTkinter TTk Compatibility Test")

app.grid_rowconfigure(0, weight=1)
app.grid_columnconfigure((0, 1, 2, 3, 5, 6), weight=1)


button_0 = customtkinter.CTkButton(app)
button_0.grid(padx=20, pady=20, row=0, column=0)

frame_1 = tkinter.Frame(master=app)
frame_1.grid(padx=20, pady=20, row=0, column=1, sticky="nsew")
button_1 = customtkinter.CTkButton(frame_1, text="tkinter.Frame")
button_1.pack(pady=20, padx=20)

frame_2 = tkinter.LabelFrame(master=app, text="Tkinter LabelFrame")
frame_2.grid(padx=20, pady=20, row=0, column=2, sticky="nsew")
button_2 = customtkinter.CTkButton(frame_2, text="tkinter.LabelFrame")
button_2.pack(pady=20, padx=20)

frame_3 = customtkinter.CTkFrame(master=app)
frame_3.grid(padx=20, pady=20, row=0, column=3, sticky="nsew")
label_3 = customtkinter.CTkLabel(master=frame_3, text="CTkFrame Label", fg_color=("gray95", "gray15"))
label_3.grid(row=0, column=0, columnspan=1, padx=5, pady=5, sticky="ew")