mirror of
https://github.com/TomSchimansky/CustomTkinter.git
synced 2023-08-10 21:13:13 +03:00
added iconify test
This commit is contained in:
parent
3eb0d411c5
commit
72823a41bc
@ -33,17 +33,17 @@ class ScalingTracker:
|
||||
|
||||
@classmethod
|
||||
def set_widget_scaling(cls, widget_scaling_factor):
|
||||
cls.widget_scaling = widget_scaling_factor
|
||||
cls.widget_scaling = max(widget_scaling_factor, 0.4)
|
||||
cls.update_scaling_callbacks()
|
||||
|
||||
@classmethod
|
||||
def set_spacing_scaling(cls, spacing_scaling_factor):
|
||||
cls.spacing_scaling = spacing_scaling_factor
|
||||
cls.spacing_scaling = max(spacing_scaling_factor, 0.4)
|
||||
cls.update_scaling_callbacks()
|
||||
|
||||
@classmethod
|
||||
def set_window_scaling(cls, window_scaling_factor):
|
||||
cls.window_scaling = window_scaling_factor
|
||||
cls.window_scaling = max(window_scaling_factor, 0.4)
|
||||
cls.update_scaling_callbacks()
|
||||
|
||||
@classmethod
|
||||
|
@ -5,6 +5,7 @@ import os
|
||||
import platform
|
||||
import ctypes
|
||||
import re
|
||||
from typing import Union
|
||||
|
||||
from ..appearance_mode_tracker import AppearanceModeTracker
|
||||
from ..theme_manager import CTkThemeManager
|
||||
@ -32,6 +33,8 @@ class CTk(tkinter.Tk):
|
||||
|
||||
self.current_width = 600 # initial window size, always without scaling
|
||||
self.current_height = 500
|
||||
self.minsize: Union[tuple, None] = None
|
||||
self.maxsize: Union[tuple, None] = None
|
||||
|
||||
self.fg_color = CTkThemeManager.theme["color"]["window_bg_color"] if fg_color == "default_theme" else fg_color
|
||||
|
||||
|
@ -134,16 +134,10 @@ class CTkToplevel(tkinter.Toplevel):
|
||||
args[0]["background"] = CTkThemeManager.single_color(self.fg_color, self.appearance_mode)
|
||||
|
||||
if bg_changed:
|
||||
from .ctk_slider import CTkSlider
|
||||
from .ctk_progressbar import CTkProgressBar
|
||||
from .ctk_label import CTkLabel
|
||||
from .ctk_frame import CTkFrame
|
||||
from .ctk_entry import CTkEntry
|
||||
from customtkinter.widgets.ctk_checkbox import CTkCheckBox
|
||||
from customtkinter.widgets.ctk_button import CTkButton
|
||||
from ..widgets.widget_base_class import CTkBaseClass
|
||||
|
||||
for child in self.winfo_children():
|
||||
if isinstance(child, (CTkFrame, CTkButton, CTkLabel, CTkSlider, CTkCheckBox, CTkEntry, CTkProgressBar)):
|
||||
if isinstance(child, CTkBaseClass):
|
||||
child.configure(bg_color=self.fg_color)
|
||||
|
||||
super().configure(*args, **kwargs)
|
||||
|
18
test/test_iconify_destroy.py
Normal file
18
test/test_iconify_destroy.py
Normal file
@ -0,0 +1,18 @@
|
||||
import tkinter
|
||||
import customtkinter
|
||||
|
||||
root_tk = customtkinter.CTk()
|
||||
root_tk.geometry("400x240")
|
||||
|
||||
def button_function():
|
||||
root_tk.iconify()
|
||||
root_tk.after(1000, root_tk.deiconify)
|
||||
root_tk.after(2000, root_tk.destroy)
|
||||
|
||||
frame = tkinter.Frame()
|
||||
frame.pack(padx=10, pady=10, expand=True, fill="both")
|
||||
|
||||
button = customtkinter.CTkButton(frame, command=button_function)
|
||||
button.pack(pady=20, padx=20)
|
||||
|
||||
root_tk.mainloop()
|
206
test/test_scaling/complex_example.py
Normal file
206
test/test_scaling/complex_example.py
Normal file
@ -0,0 +1,206 @@
|
||||
import tkinter
|
||||
import tkinter.messagebox
|
||||
import customtkinter
|
||||
|
||||
customtkinter.set_appearance_mode("System") # Modes: "System" (standard), "Dark", "Light"
|
||||
customtkinter.set_default_color_theme("blue") # Themes: "blue" (standard), "green", "dark-blue"
|
||||
|
||||
|
||||
class App(customtkinter.CTk):
|
||||
|
||||
WIDTH = 780
|
||||
HEIGHT = 520
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
self.title("CustomTkinter complex example")
|
||||
self.geometry(f"{App.WIDTH}x{App.HEIGHT}")
|
||||
# self.minsize(App.WIDTH, 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=None)
|
||||
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=lambda x: customtkinter.set_user_scaling(x * 2))
|
||||
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()
|
||||
|
||||
def button_event(self):
|
||||
print("Button pressed")
|
||||
|
||||
def change_mode(self):
|
||||
if self.switch_2.get() == 1:
|
||||
customtkinter.set_appearance_mode("dark")
|
||||
else:
|
||||
customtkinter.set_appearance_mode("light")
|
||||
|
||||
def on_closing(self, event=0):
|
||||
self.destroy()
|
||||
|
||||
def start(self):
|
||||
self.mainloop()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = App()
|
||||
app.start()
|
76
test/test_scaling/example_background_image.py
Normal file
76
test/test_scaling/example_background_image.py
Normal file
@ -0,0 +1,76 @@
|
||||
import tkinter
|
||||
import tkinter.messagebox
|
||||
import customtkinter
|
||||
from PIL import Image, ImageTk
|
||||
import os
|
||||
|
||||
customtkinter.ScalingTracker.set_window_scaling(1.5)
|
||||
customtkinter.ScalingTracker.set_widget_scaling(1.5)
|
||||
customtkinter.ScalingTracker.set_spacing_scaling(1.5)
|
||||
|
||||
|
||||
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__))
|
||||
|
||||
|
||||
class App(customtkinter.CTk):
|
||||
|
||||
APP_NAME = "CustomTkinter background gradient image"
|
||||
WIDTH = 900
|
||||
HEIGHT = 600
|
||||
|
||||
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.protocol("WM_DELETE_WINDOW", self.on_closing)
|
||||
self.bind("<Command-q>", self.on_closing)
|
||||
self.bind("<Command-w>", self.on_closing)
|
||||
self.createcommand('tk::mac::Quit', 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", "gray35"), 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=20, 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=20, 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 button_event(self):
|
||||
print("Login pressed - username:", self.entry_1.get(), "password:", self.entry_2.get())
|
||||
|
||||
def on_closing(self, event=0):
|
||||
self.destroy()
|
||||
|
||||
def start(self):
|
||||
self.mainloop()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = App()
|
||||
app.start()
|
@ -2,8 +2,6 @@ import tkinter
|
||||
import customtkinter # <- import the CustomTkinter module
|
||||
|
||||
customtkinter.ScalingTracker.set_window_scaling(1.5)
|
||||
customtkinter.ScalingTracker.set_spacing_scaling(1.5)
|
||||
customtkinter.ScalingTracker.set_widget_scaling(1.5)
|
||||
|
||||
customtkinter.set_appearance_mode("dark") # Modes: "System" (standard), "Dark", "Light"
|
||||
customtkinter.set_default_color_theme("blue") # Themes: "blue" (standard), "green", "dark-blue"
|
||||
@ -19,6 +17,7 @@ def button_function():
|
||||
|
||||
|
||||
def slider_function(value):
|
||||
customtkinter.set_user_scaling(value * 2)
|
||||
progressbar_1.set(value)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user