mirror of
https://github.com/TomSchimansky/CustomTkinter.git
synced 2023-08-10 21:13:13 +03:00
worked on CTkTabview, fixed small issues
This commit is contained in:
@ -12,14 +12,14 @@ class App(customtkinter.CTk):
|
||||
super().__init__()
|
||||
|
||||
self.title("CustomTkinter complex_example.py")
|
||||
self.geometry(f"{920}x{500}")
|
||||
self.minsize(700, 400)
|
||||
self.maxsize(1200, 700)
|
||||
self.geometry(f"{1100}x{580}")
|
||||
self.minsize(800, 400)
|
||||
self.maxsize(1300, 700)
|
||||
self.protocol("WM_DELETE_WINDOW", self.on_closing) # call .on_closing() when app gets closed
|
||||
|
||||
# configure grid layout (4x4)
|
||||
self.grid_columnconfigure(1, weight=1)
|
||||
self.grid_columnconfigure((2, 3), weight=0, minsize=200)
|
||||
self.grid_columnconfigure((2, 3, 4), weight=0, minsize=200)
|
||||
self.grid_rowconfigure((0, 1, 2), weight=1)
|
||||
|
||||
# create sidebar frame with widgets
|
||||
@ -52,22 +52,10 @@ class App(customtkinter.CTk):
|
||||
self.main_button_1 = customtkinter.CTkButton(master=self, fg_color=None, border_width=2)
|
||||
self.main_button_1.grid(row=3, column=3, padx=(10, 20), pady=(10, 20), sticky="nsew")
|
||||
|
||||
# create textbox
|
||||
self.textbox = customtkinter.CTkTextbox(self)
|
||||
self.textbox.grid(row=0, column=1, padx=(20, 10), pady=(20, 10), sticky="nsew")
|
||||
|
||||
# create radiobutton frame
|
||||
self.radiobutton_frame = customtkinter.CTkFrame(self)
|
||||
self.radiobutton_frame.grid(row=0, column=3, padx=(10, 20), pady=(20, 10), sticky="nsew")
|
||||
self.radio_var = tkinter.IntVar(value=0)
|
||||
self.label_radio_group = customtkinter.CTkLabel(master=self.radiobutton_frame, text="CTkRadioButton Group:")
|
||||
self.label_radio_group.grid(row=0, column=2, columnspan=1, padx=10, pady=10, sticky="")
|
||||
self.radio_button_1 = customtkinter.CTkRadioButton(master=self.radiobutton_frame, 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.radiobutton_frame, 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.radiobutton_frame, variable=self.radio_var, value=2)
|
||||
self.radio_button_3.grid(row=3, column=2, pady=10, padx=20, sticky="n")
|
||||
|
||||
# create optionemnu and combobox frame
|
||||
self.optionemnu_combobox_frame = customtkinter.CTkFrame(self)
|
||||
self.optionemnu_combobox_frame.grid(row=0, column=2, padx=(10, 10), pady=(20, 10), sticky="nsew")
|
||||
@ -82,9 +70,22 @@ class App(customtkinter.CTk):
|
||||
command=self.open_input_dialog)
|
||||
self.string_input_button.grid(row=2, column=0, padx=20, pady=(10, 10), sticky="ew")
|
||||
|
||||
# create radiobutton frame
|
||||
self.radiobutton_frame = customtkinter.CTkFrame(self)
|
||||
self.radiobutton_frame.grid(row=0, column=3, padx=(10, 10), pady=(20, 10), sticky="nsew")
|
||||
self.radio_var = tkinter.IntVar(value=0)
|
||||
self.label_radio_group = customtkinter.CTkLabel(master=self.radiobutton_frame, text="CTkRadioButton Group:")
|
||||
self.label_radio_group.grid(row=0, column=2, columnspan=1, padx=10, pady=10, sticky="")
|
||||
self.radio_button_1 = customtkinter.CTkRadioButton(master=self.radiobutton_frame, 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.radiobutton_frame, 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.radiobutton_frame, variable=self.radio_var, value=2)
|
||||
self.radio_button_3.grid(row=3, column=2, pady=10, padx=20, sticky="n")
|
||||
|
||||
# create checkbox and switch frame
|
||||
self.checkbox_slider_frame = customtkinter.CTkFrame(self)
|
||||
self.checkbox_slider_frame.grid(row=1, column=3, padx=(10, 20), pady=(10, 10), sticky="nsew")
|
||||
self.checkbox_slider_frame.grid(row=0, column=4, padx=(10, 20), pady=(20, 10), sticky="nsew")
|
||||
self.checkbox_1 = customtkinter.CTkCheckBox(master=self.checkbox_slider_frame)
|
||||
self.checkbox_1.grid(row=1, column=0, pady=(20, 10), padx=20, sticky="n")
|
||||
self.checkbox_2 = customtkinter.CTkCheckBox(master=self.checkbox_slider_frame)
|
||||
@ -100,9 +101,8 @@ class App(customtkinter.CTk):
|
||||
self.slider_progressbar_frame.grid_columnconfigure(0, weight=1)
|
||||
self.slider_progressbar_frame.grid_rowconfigure(4, weight=1)
|
||||
|
||||
self.seg_button = customtkinter._CTkSegmentedButton(self.slider_progressbar_frame,
|
||||
values=["CTkSegmentedButton", "Value 2", "Value 3"])
|
||||
self.seg_button.grid(row=0, column=0, padx=(20, 10), pady=(10, 10), sticky="ew")
|
||||
self.seg_button_1 = customtkinter._CTkSegmentedButton(self.slider_progressbar_frame)
|
||||
self.seg_button_1.grid(row=0, column=0, padx=(20, 10), pady=(10, 10), sticky="ew")
|
||||
|
||||
self.progressbar_1 = customtkinter.CTkProgressBar(self.slider_progressbar_frame)
|
||||
self.progressbar_1.grid(row=1, column=0, padx=(20, 10), pady=(10, 10), sticky="ew")
|
||||
@ -115,6 +115,10 @@ class App(customtkinter.CTk):
|
||||
self.progressbar_3 = customtkinter.CTkProgressBar(self.slider_progressbar_frame, orientation="vertical")
|
||||
self.progressbar_3.grid(row=0, column=2, rowspan=5, padx=(10, 20), pady=(10, 10), sticky="ns")
|
||||
|
||||
# create tabview
|
||||
self.tabview = customtkinter._CTkTabview(self)
|
||||
self.tabview.grid(row=1, column=3, columnspan=2, padx=(10, 20), pady=(10, 10), sticky="nsew")
|
||||
|
||||
# set default values
|
||||
self.sidebar_button_3.configure(state="disabled", text="Disabled CTkButton")
|
||||
self.checkbox_2.configure(state="disabled")
|
||||
@ -130,8 +134,11 @@ class App(customtkinter.CTk):
|
||||
self.slider_2.configure(command=self.progressbar_3.set)
|
||||
self.progressbar_1.configure(mode="indeterminnate")
|
||||
self.progressbar_1.start()
|
||||
self.textbox.insert("0.0", "CTkTextbox\n\n" + "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.\n\n" * 20)
|
||||
self.seg_button_1.configure(values=["CTkSegmentedButton", "Value 2", "Value 3"])
|
||||
self.seg_button_1.set("Value 2")
|
||||
|
||||
self.textbox.insert("1.0", "CTkTextbox\n\n" + "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.\n\n" * 20)
|
||||
self.radiobutton_frame.configure(border_width=50)
|
||||
|
||||
def open_input_dialog(self):
|
||||
dialog = customtkinter.CTkInputDialog(master=self, text="Type in a number:", title="CTkInputDialog")
|
||||
|
@ -2,7 +2,7 @@ import tkinter
|
||||
import customtkinter
|
||||
|
||||
customtkinter.set_appearance_mode("System") # Other: "Dark", "Light"
|
||||
customtkinter.set_default_color_theme("green") # Themes: "blue" (standard), "green", "dark-blue"
|
||||
# customtkinter.set_default_color_theme("green") # Themes: "blue" (standard), "green", "dark-blue"
|
||||
|
||||
|
||||
class TestApp(customtkinter.CTk):
|
||||
@ -20,13 +20,13 @@ class TestApp(customtkinter.CTk):
|
||||
""" gets called by self.slider_1 """
|
||||
|
||||
if value == 0:
|
||||
self.label_1.set_text("mode: Light")
|
||||
self.label_1.configure(text="mode: Light")
|
||||
customtkinter.set_appearance_mode("Light")
|
||||
elif value == 1:
|
||||
self.label_1.set_text("mode: Dark")
|
||||
self.label_1.configure(text="mode: Dark")
|
||||
customtkinter.set_appearance_mode("Dark")
|
||||
else:
|
||||
self.label_1.set_text("mode: System")
|
||||
self.label_1.configure(text="mode: System")
|
||||
customtkinter.set_appearance_mode("System")
|
||||
|
||||
def create_widgets_on_tk(self):
|
||||
@ -74,7 +74,7 @@ class TestApp(customtkinter.CTk):
|
||||
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 = customtkinter.CTkSlider(master=self.ctk_frame, command=lambda v: self.label_2.configure(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)
|
||||
@ -102,7 +102,7 @@ class TestApp(customtkinter.CTk):
|
||||
self.ctk_frame_customized.configure(fg_color=("#F4F4FA", "#1E2742"))
|
||||
|
||||
self.label_3 = customtkinter.CTkLabel(master=self.ctk_frame_customized, text="customized", corner_radius=60,
|
||||
text_font=("times", 16))
|
||||
font=("times", 16))
|
||||
self.label_3.place(relx=0.5, y=y, anchor=tkinter.CENTER)
|
||||
self.label_3.configure(fg_color=("#F4F4FA", "#333D5E"), text_color=("#373E57", "#7992C1"))
|
||||
|
||||
@ -111,12 +111,12 @@ class TestApp(customtkinter.CTk):
|
||||
self.frame_3.configure(fg_color=("#EBECF3", "#4B577E"))
|
||||
|
||||
self.button_3 = customtkinter.CTkButton(master=self.ctk_frame_customized, command=lambda: x, border_width=3,
|
||||
corner_radius=20, text_font=("times", 16))
|
||||
corner_radius=20, font=("times", 16))
|
||||
self.button_3.place(relx=0.5, y=y + 160, anchor=tkinter.CENTER)
|
||||
self.button_3.configure(border_color=("#4F90F8", "#6FADF9"), hover_color=("#3A65E8", "#4376EE"))
|
||||
self.button_3.configure(fg_color=None)
|
||||
|
||||
self.entry_3 = customtkinter.CTkEntry(master=self.ctk_frame_customized, text_font=("times", 16))
|
||||
self.entry_3 = customtkinter.CTkEntry(master=self.ctk_frame_customized, font=("times", 16))
|
||||
self.entry_3.place(relx=0.5, y=y + 240, anchor=tkinter.CENTER)
|
||||
self.entry_3.configure(fg_color=("gray60", "gray5"), corner_radius=20)
|
||||
self.entry_3.insert(0, "1234567890")
|
||||
@ -131,7 +131,7 @@ class TestApp(customtkinter.CTk):
|
||||
self.slider_3.configure(button_color="#8AE0C3", fg_color=("#EBECF3", "#4B577E"), progress_color=("gray30", "gray10"))
|
||||
self.slider_3.configure(from_=0, to=1)
|
||||
|
||||
self.check_box_3 = customtkinter.CTkCheckBox(master=self.ctk_frame_customized, corner_radius=50, text_font=("times", 16))
|
||||
self.check_box_3 = customtkinter.CTkCheckBox(master=self.ctk_frame_customized, corner_radius=50, font=("times", 16))
|
||||
self.check_box_3.place(relx=0.5, y=y + 480, anchor=tkinter.CENTER)
|
||||
self.check_box_3.configure(border_color="#8AE0C3")
|
||||
|
||||
@ -176,4 +176,4 @@ class TestApp(customtkinter.CTk):
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_app = TestApp()
|
||||
test_app.mainloop()
|
||||
test_app.mainloop()
|
||||
|
@ -1,6 +1,5 @@
|
||||
import tkinter
|
||||
import tkinter.messagebox
|
||||
from tkinter import filedialog as fd
|
||||
import customtkinter
|
||||
|
||||
|
||||
@ -23,35 +22,31 @@ class App(customtkinter.CTk):
|
||||
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)
|
||||
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)
|
||||
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))
|
||||
fg_color=None, hover_color=App.MAIN_HOVER,
|
||||
height=28, text="Output Folder", command=self.button_outputFunc,
|
||||
border_width=3, corner_radius=10, 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)
|
||||
|
||||
def button_outputFunc(self):
|
||||
self.entry_output.delete(0, 'end')
|
||||
filename = fd.askdirectory()
|
||||
self.entry_output.insert(0,str(filename))
|
||||
pass
|
||||
filename = customtkinter.filedialog.askdirectory()
|
||||
self.entry_output.insert(0, str(filename))
|
||||
|
||||
def on_closing(self, event=0):
|
||||
self.destroy()
|
||||
|
@ -7,7 +7,8 @@ app.geometry("600x950")
|
||||
switch_1 = customtkinter.CTkSwitch(app, text="darkmode", command=lambda: customtkinter.set_appearance_mode("dark" if switch_1.get() == 1 else "light"))
|
||||
switch_1.pack(padx=20, pady=20)
|
||||
|
||||
seg_1 = customtkinter._CTkSegmentedButton(app, values=["value 1", "Value 2", "Value 42", "Value 123", "longlonglong"])
|
||||
seg_1 = customtkinter._CTkSegmentedButton(app, values=[])
|
||||
seg_1.configure(values=["value 1", "Value 2", "Value 42", "Value 123", "longlonglong"])
|
||||
seg_1.pack(padx=20, pady=20)
|
||||
|
||||
frame_1 = customtkinter.CTkFrame(app, height=100)
|
||||
@ -16,22 +17,23 @@ frame_1.pack(padx=20, pady=20, fill="x")
|
||||
seg_2_var = customtkinter.StringVar(value="value 1")
|
||||
|
||||
seg_2 = customtkinter._CTkSegmentedButton(frame_1, values=["value 1", "Value 2", "Value 42"], variable=seg_2_var)
|
||||
seg_2.pack(padx=20, pady=20)
|
||||
|
||||
seg_2.insert_value(0, "insert at 0")
|
||||
seg_2.insert_value(1, "insert at 1")
|
||||
seg_2.configure(values=[])
|
||||
seg_2.configure(values=["value 1", "Value 2", "Value 42"])
|
||||
seg_2.pack(padx=20, pady=10)
|
||||
seg_2.insert(0, "insert at 0")
|
||||
seg_2.insert(1, "insert at 1")
|
||||
|
||||
label_seg_2 = customtkinter.CTkLabel(frame_1, textvariable=seg_2_var)
|
||||
label_seg_2.pack(padx=20, pady=20)
|
||||
label_seg_2.pack(padx=20, pady=10)
|
||||
|
||||
frame_1_1 = customtkinter.CTkFrame(frame_1, height=100)
|
||||
frame_1_1.pack(padx=20, pady=20, fill="x")
|
||||
frame_1_1.pack(padx=20, pady=10, fill="x")
|
||||
|
||||
switch_2 = customtkinter.CTkSwitch(frame_1_1, text="change fg", command=lambda: frame_1_1.configure(fg_color="red" if switch_2.get() == 1 else "green"))
|
||||
switch_2.pack(padx=20, pady=20)
|
||||
|
||||
seg_3 = customtkinter._CTkSegmentedButton(frame_1_1, values=["value 1", "Value 2", "Value 42"])
|
||||
seg_3.pack(padx=20, pady=20)
|
||||
seg_3.pack(padx=20, pady=10)
|
||||
|
||||
seg_4 = customtkinter._CTkSegmentedButton(app)
|
||||
seg_4.pack(padx=20, pady=20)
|
||||
@ -41,14 +43,14 @@ seg_5 = customtkinter._CTkSegmentedButton(app, corner_radius=1000, border_width=
|
||||
variable=seg_5_var)
|
||||
seg_5.pack(padx=20, pady=20)
|
||||
seg_5.configure(values=["1", "2", "3", "4"])
|
||||
seg_5.insert_value(0, "insert begin")
|
||||
seg_5.insert_value(len(seg_5.cget("values")), "insert 1")
|
||||
seg_5.insert_value(len(seg_5.cget("values")), "insert 2")
|
||||
seg_5.insert_value(len(seg_5.cget("values")), "insert 3")
|
||||
seg_5.insert(0, "insert begin")
|
||||
seg_5.insert(len(seg_5.cget("values")), "insert 1")
|
||||
seg_5.insert(len(seg_5.cget("values")), "insert 2")
|
||||
seg_5.insert(len(seg_5.cget("values")), "insert 3")
|
||||
seg_5.configure(fg_color="green")
|
||||
|
||||
seg_5.set("insert 2")
|
||||
seg_5.remove_value("insert 2")
|
||||
seg_5.delete("insert 2")
|
||||
|
||||
label_seg_5 = customtkinter.CTkLabel(app, textvariable=seg_5_var)
|
||||
label_seg_5.pack(padx=20, pady=20)
|
||||
@ -58,14 +60,19 @@ seg_6 = customtkinter._CTkSegmentedButton(app, width=300)
|
||||
seg_6.pack(padx=20, pady=20)
|
||||
entry_6 = customtkinter.CTkEntry(app)
|
||||
entry_6.pack(padx=20, pady=(0, 20))
|
||||
button_6 = customtkinter.CTkButton(app, text="set", command=lambda: seg_6.set(entry_6.get()), corner_radius=1000)
|
||||
button_6 = customtkinter.CTkButton(app, text="set", command=lambda: seg_6.set(entry_6.get()))
|
||||
button_6.pack(padx=20, pady=(0, 20))
|
||||
button_6 = customtkinter.CTkButton(app, text="insert value", command=lambda: seg_6.insert_value(0, entry_6.get()))
|
||||
button_6 = customtkinter.CTkButton(app, text="insert value", command=lambda: seg_6.insert(0, entry_6.get()))
|
||||
button_6.pack(padx=20, pady=(0, 20))
|
||||
label_6 = customtkinter.CTkLabel(app, textvariable=seg_6_var)
|
||||
label_6.pack(padx=20, pady=(0, 20))
|
||||
|
||||
seg_6.configure(height=50, variable=seg_6_var)
|
||||
seg_6.remove_value("CTkSegmentedButton")
|
||||
seg_6.delete("CTkSegmentedButton")
|
||||
|
||||
seg_7 = customtkinter._CTkSegmentedButton(app, values=["disabled seg button", "2", "3"])
|
||||
seg_7.pack(padx=20, pady=20)
|
||||
seg_7.configure(state="disabled")
|
||||
seg_7.set("2")
|
||||
|
||||
app.mainloop()
|
||||
|
@ -1,16 +1,14 @@
|
||||
import customtkinter
|
||||
import tkinter.ttk as ttk
|
||||
|
||||
app = customtkinter.CTk()
|
||||
|
||||
tabview = customtkinter._CTkTabview(app)
|
||||
tabview.pack(pady=20, padx=20)
|
||||
tabview_1 = customtkinter._CTkTabview(app)
|
||||
tabview_1.pack(padx=20, pady=20)
|
||||
tabview_1.add("tab 1")
|
||||
tabview_1.insert(0, "tab 0 g |ß$§")
|
||||
|
||||
tabview.create_tab(identifier="tab1", text="Tab 1")
|
||||
tabview.select_tab("tab1")
|
||||
app.update()
|
||||
|
||||
|
||||
switch = customtkinter.CTkSwitch(app, text="Darkmode", onvalue="dark", offvalue="light",
|
||||
command=lambda: customtkinter.set_appearance_mode(switch.get()))
|
||||
switch.pack(padx=20, pady=20)
|
||||
tabview_1._segmented_button._buttons_dict["tab 0 g |ß$§"]._text_label.configure(padx=0, pady=0, bd=0)
|
||||
tabview_1._segmented_button._buttons_dict["tab 0 g |ß$§"]._text_label.configure(bg="red")
|
||||
app.mainloop()
|
||||
|
Reference in New Issue
Block a user