Beispiel #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)
Beispiel #2
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")
Beispiel #3
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)
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,
                                             value=1)
radiobutton_1.pack(pady=y_padding, padx=10)
radiobutton_2 = customtkinter.CTkRadioButton(master=frame_1,
                                             variable=radiobutton_var,
                                             value=2)
radiobutton_2.pack(pady=y_padding, padx=10)
s_var = tkinter.StringVar(value="on")
switch_1 = customtkinter.CTkSwitch(master=frame_1)
switch_1.pack(pady=y_padding, padx=10)

label_1 = customtkinter.CTkLabel(master=top_tk, justify=tkinter.LEFT)
Beispiel #5
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()
slider_2.pack(pady=15)
if TEST_CONFIGURE: slider_2.configure(variable=int_var)
if TEST_REMOVING: slider_2.configure(variable="")

label_2 = customtkinter.CTkLabel(app, width=200, textvariable=int_var)
label_2.pack(pady=15)

progress_1 = customtkinter.CTkProgressBar(app, width=200, variable=int_var)
progress_1.pack(pady=15)
if TEST_CONFIGURE: progress_1.configure(variable=int_var)
if TEST_REMOVING: progress_1.configure(variable="")

check_var = tkinter.StringVar(value="on")
check_1 = customtkinter.CTkCheckBox(app,
                                    text="check 1",
                                    variable=check_var,
                                    onvalue="on",
                                    offvalue="off")
check_1.pack(pady=15)
if TEST_CONFIGURE: check_1.configure(variable=check_var)
if TEST_REMOVING: check_1.configure(variable="")
print("check_1", check_1.get())

check_2 = customtkinter.CTkCheckBox(app,
                                    text="check 2",
                                    variable=check_var,
                                    onvalue="on",
                                    offvalue="off")
check_2.pack(pady=15)
if TEST_CONFIGURE: check_2.configure(variable=check_var)
if TEST_REMOVING: check_2.configure(variable="")
                                   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))

entry_1 = customtkinter.CTkEntry(master=app, placeholder_text="entry_1")
entry_1.pack(padx=20, pady=(20, 10))
button_3 = customtkinter.CTkButton(master=app,
                                   text="Disable/Enable entry_1",
                                   command=lambda: change_state(entry_1))
button_3.pack(padx=20, pady=(10, 20))

checkbox_1 = customtkinter.CTkCheckBox(master=app, text="checkbox_1")
checkbox_1.pack(padx=20, pady=(20, 10))
button_4 = customtkinter.CTkButton(master=app,
                                   text="Disable/Enable checkbox_1",
                                   command=lambda: change_state(checkbox_1))
button_4.pack(padx=20, pady=(10, 20))

radiobutton_1 = customtkinter.CTkRadioButton(master=app, text="radiobutton_1")
radiobutton_1.pack(padx=20, pady=(20, 10))
button_5 = customtkinter.CTkButton(master=app,
                                   text="Disable/Enable radiobutton_1",
                                   command=lambda: change_state(radiobutton_1))
button_5.pack(padx=20, pady=(10, 20))

optionmenu_1 = customtkinter.CTkOptionMenu(app, values=["test 1", "test 2"])
optionmenu_1.pack(pady=10, padx=10)
    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()