fixed some configure bugs #585 #584 #583 #580 #579 #578, added check_image method

This commit is contained in:
Tom Schimansky
2022-11-06 14:40:15 +01:00
parent 62b330ddba
commit cea48c3501
16 changed files with 144 additions and 102 deletions

View File

@ -11,11 +11,9 @@ class App(customtkinter.CTk):
def __init__(self):
super().__init__()
# configure window
self.title("CustomTkinter complex_example.py")
self.geometry(f"{1100}x{580}")
#self.minsize(800, 400)
#self.maxsize(1200, 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)
@ -62,19 +60,20 @@ class App(customtkinter.CTk):
self.tabview.add("CTkTabview")
self.tabview.add("Tab 2")
self.tabview.add("Tab 3")
self.tabview.tab("CTkTabview").grid_columnconfigure(0, weight=1) # configure grid of individual tabs
self.tabview.tab("Tab 2").grid_columnconfigure(0, weight=1)
self.tabview.tab("CTkTabview").grid_columnconfigure(0, weight=1)
self.optionmenu_1 = customtkinter.CTkOptionMenu(self.tabview.tab("CTkTabview"),
dynamic_resizing=False,
self.optionmenu_1 = customtkinter.CTkOptionMenu(self.tabview.tab("CTkTabview"), dynamic_resizing=False,
values=["Value 1", "Value 2", "Value Long Long Long"])
self.optionmenu_1.grid(row=0, column=0, padx=20, pady=(20, 10))
self.combobox_1 = customtkinter.CTkComboBox(self.tabview.tab("CTkTabview"),
values=["Value 1", "Value 2", "Value Long....."])
self.combobox_1.grid(row=1, column=0, padx=20, pady=(10, 10))
self.string_input_button = customtkinter.CTkButton(self.tabview.tab("CTkTabview"),
text="Open CTkInputDialog",
self.string_input_button = customtkinter.CTkButton(self.tabview.tab("CTkTabview"), text="Open CTkInputDialog",
command=self.open_input_dialog)
self.string_input_button.grid(row=2, column=0, padx=20, pady=(10, 10))
self.label_tab_2 = customtkinter.CTkLabel(self.tabview.tab("Tab 2"), text="CTkLabel on Tab 2")
self.label_tab_2.grid(row=0, column=0, padx=20, pady=20)
# create radiobutton frame
self.radiobutton_frame = customtkinter.CTkFrame(self)
@ -106,10 +105,8 @@ class App(customtkinter.CTk):
self.slider_progressbar_frame.grid(row=1, column=1, columnspan=2, padx=(20, 0), pady=(20, 0), sticky="nsew")
self.slider_progressbar_frame.grid_columnconfigure(0, weight=1)
self.slider_progressbar_frame.grid_rowconfigure(4, weight=1)
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")
self.progressbar_2 = customtkinter.CTkProgressBar(self.slider_progressbar_frame)
@ -154,9 +151,6 @@ class App(customtkinter.CTk):
def sidebar_button_callback(self):
print("sidebar_button click")
def on_closing(self, event=0):
self.destroy()
if __name__ == "__main__":
app = App()

View File

@ -1,13 +1,9 @@
import tkinter
import tkinter.messagebox
import customtkinter
from PIL import Image, ImageTk
from PIL import Image
import os
customtkinter.set_appearance_mode("Dark") # Modes: "System" (standard), "Dark", "Light"
customtkinter.set_default_color_theme("blue") # Themes: "blue" (standard), "green", "dark-blue"
PATH = os.path.dirname(os.path.realpath(__file__))
customtkinter.set_appearance_mode("dark")
class App(customtkinter.CTk):
@ -28,10 +24,11 @@ class App(customtkinter.CTk):
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)
current_path = os.path.dirname(os.path.realpath(__file__))
self.bg_image = customtkinter.CTkImage(Image.open(current_path + "/test_images/bg_gradient.jpg"),
size=(self.WIDTH, self.HEIGHT))
self.image_label = tkinter.Label(master=self, image=self.bg_image)
self.image_label = customtkinter.CTkLabel(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,
@ -40,7 +37,7 @@ class App(customtkinter.CTk):
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,
self.label_1 = customtkinter.CTkLabel(master=self.frame, width=200, height=60, corner_radius=6,
fg_color=("gray70", "gray25"), text="CustomTkinter\ninterface example")
self.label_1.place(relx=0.5, rely=0.3, anchor=tkinter.CENTER)

View File

@ -1,35 +0,0 @@
import customtkinter
from PIL import Image, ImageTk
import os
# load images
file_path = os.path.dirname(os.path.realpath(__file__))
image_1 = customtkinter.CTkImage(light_image=Image.open(file_path + "/test_images/add_folder_dark.png"),
dark_image=Image.open(file_path + "/test_images/add_folder_light.png"),
size=(30, 30))
image_1.configure(dark_image=Image.open(file_path + "/test_images/add_folder_light.png"))
image_2 = customtkinter.CTkImage(light_image=Image.open(file_path + "/test_images/bg_gradient.jpg"),
size=(30, 50))
app = customtkinter.CTk()
mode_switch = customtkinter.CTkSwitch(app, text="darkmode",
command=lambda: customtkinter.set_appearance_mode("dark" if mode_switch.get() == 1 else "light"))
mode_switch.pack(padx=20, pady=20)
scaling_button = customtkinter.CTkSegmentedButton(app, values=[0.8, 0.9, 1.0, 1.1, 1.2, 1.5, 2.0],
command=lambda v: customtkinter.set_widget_scaling(v))
scaling_button.pack(padx=20, pady=20)
button_1 = customtkinter.CTkButton(app, image=image_1)
button_1.pack(padx=20, pady=20)
label_1 = customtkinter.CTkLabel(app, text="", image=image_2, compound="right", fg_color="green", width=0)
label_1.pack(padx=20, pady=20)
label_1.configure(image=image_1)
label_2 = customtkinter.CTkLabel(app, image=ImageTk.PhotoImage(Image.open(file_path + "/test_images/bg_gradient.jpg").resize((100, 100))),
text="", compound="right", fg_color="green", width=0)
label_2.pack(padx=20, pady=20)
app.mainloop()

View File

@ -5,7 +5,7 @@ customtkinter.set_appearance_mode("dark") # Modes: "System" (standard), "Dark",
customtkinter.set_default_color_theme("blue") # Themes: "blue" (standard), "green", "dark-blue"
app = customtkinter.CTk()
app.geometry("400x580")
app.geometry("400x780")
app.title("CustomTkinter simple_example.py")
@ -21,41 +21,53 @@ 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)
label_1.pack(pady=10, padx=10)
progressbar_1 = customtkinter.CTkProgressBar(master=frame_1)
progressbar_1.pack(pady=12, padx=10)
progressbar_1.pack(pady=10, padx=10)
button_1 = customtkinter.CTkButton(master=frame_1, command=button_callback)
button_1.pack(pady=12, padx=10)
button_1.pack(pady=10, 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.pack(pady=10, padx=10)
slider_1.set(0.5)
entry_1 = customtkinter.CTkEntry(master=frame_1, placeholder_text="CTkEntry")
entry_1.pack(pady=12, padx=10)
entry_1.pack(pady=10, padx=10)
optionmenu_1 = customtkinter.CTkOptionMenu(frame_1, values=["Option 1", "Option 2", "Option 42 long long long..."])
optionmenu_1.pack(pady=12, padx=10)
optionmenu_1.pack(pady=10, padx=10)
optionmenu_1.set("CTkOptionMenu")
combobox_1 = customtkinter.CTkComboBox(frame_1, values=["Option 1", "Option 2", "Option 42 long long long..."])
combobox_1.pack(pady=12, padx=10)
combobox_1.pack(pady=10, padx=10)
optionmenu_1.set("CTkComboBox")
checkbox_1 = customtkinter.CTkCheckBox(master=frame_1)
checkbox_1.pack(pady=12, padx=10)
checkbox_1.pack(pady=10, padx=10)
radiobutton_var = tkinter.IntVar(value=1)
radiobutton_1 = customtkinter.CTkRadioButton(master=frame_1, variable=radiobutton_var, value=1)
radiobutton_1.pack(pady=12, padx=10)
radiobutton_1.pack(pady=10, padx=10)
radiobutton_2 = customtkinter.CTkRadioButton(master=frame_1, variable=radiobutton_var, value=2)
radiobutton_2.pack(pady=12, padx=10)
radiobutton_2.pack(pady=10, padx=10)
switch_1 = customtkinter.CTkSwitch(master=frame_1)
switch_1.pack(pady=12, padx=10)
switch_1.pack(pady=10, padx=10)
text_1 = customtkinter.CTkTextbox(master=frame_1, width=200, height=70)
text_1.pack(pady=10, padx=10)
text_1.insert("0.0", "CTkTextbox\n\n\n\n")
segmented_button_1 = customtkinter.CTkSegmentedButton(master=frame_1, values=["CTkSegmentedButton", "Value 2"])
segmented_button_1.pack(pady=10, padx=10)
tabview_1 = customtkinter.CTkTabview(master=frame_1, width=200, height=70)
tabview_1.pack(pady=10, padx=10)
tabview_1.add("CTkTabview")
tabview_1.add("Tab 2")
app.mainloop()

View File

@ -1,51 +0,0 @@
import tkinter.ttk as ttk
import tkinter
app = tkinter.Tk()
app.geometry("400x350")
app.title("simple_example_standard_tkinter.py")
def button_function():
print("button pressed")
def slider_function(value):
progressbar_1["value"] = value
s = ttk.Style()
s.configure("TRadiobutton", fg="red")
y_padding = 6
frame_1 = tkinter.Frame(master=app, width=300, height=260, bg="lightgray")
frame_1.pack(padx=60, pady=20, fill="both", expand=True)
label_1 = tkinter.Label(master=frame_1, text="Label", bg="lightgray")
label_1.pack(pady=y_padding, padx=10)
progressbar_1 = ttk.Progressbar(master=frame_1, style='black.Horizontal.TProgressbar', length=150)
progressbar_1.pack(pady=y_padding, padx=10)
progressbar_1["value"] = 50
button_1 = tkinter.Button(master=frame_1, command=button_function, text="Button", highlightbackground="lightgray")
button_1.pack(pady=y_padding, padx=10)
slider_1 = tkinter.Scale(master=frame_1, command=slider_function, orient="horizontal", bg="lightgray", length=150)
slider_1.pack(pady=y_padding, padx=10)
entry_1 = tkinter.Entry(master=frame_1, highlightbackground="lightgray", width=10)
entry_1.pack(pady=y_padding, padx=10)
checkbox_1 = tkinter.Checkbutton(master=frame_1, bg=frame_1.cget("bg"), text="CheckButton")
checkbox_1.pack(pady=y_padding, padx=10)
radiobutton_var = tkinter.IntVar()
radiobutton_1 = ttk.Radiobutton(master=frame_1, variable=radiobutton_var, value=1, text="Radiobutton")
radiobutton_1.pack(pady=y_padding, padx=10)
radiobutton_2 = ttk.Radiobutton(master=frame_1, variable=radiobutton_var, value=2, text="Radiobutton")
radiobutton_2.pack(pady=y_padding, padx=10)
app.mainloop()

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.8 KiB