font character mapping for Windows 11, added , refined CTkDrawEngineCTkRadioButton

This commit is contained in:
TomSchimansky
2022-03-05 02:01:07 +01:00
parent eab428f9ef
commit 6c976245aa
14 changed files with 500 additions and 101 deletions

View File

@ -9,15 +9,14 @@ customtkinter.set_default_color_theme("blue") # Themes: "blue" (standard), "gre
class App(customtkinter.CTk):
APP_NAME = "CustomTkinter complex example"
WIDTH = 700
HEIGHT = 500
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def __init__(self):
super().__init__()
self.title(App.APP_NAME)
self.geometry(str(App.WIDTH) + "x" + str(App.HEIGHT))
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)
@ -26,17 +25,14 @@ class App(customtkinter.CTk):
self.bind("<Command-w>", self.on_closing)
self.createcommand('tk::mac::Quit', self.on_closing)
# ============ create two CTkFrames ============
# ============ create two frames ============
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,
width=420,
height=App.HEIGHT-40,
corner_radius=12)
self.frame_right = customtkinter.CTkFrame(master=self)
self.frame_right.grid(row=0, column=1, sticky="nswe", padx=20, pady=20)
self.grid_columnconfigure(1, weight=1)
@ -50,29 +46,25 @@ class App(customtkinter.CTk):
self.label_1 = customtkinter.CTkLabel(master=self.frame_left,
text="CustomTkinter",
text_font=("Roboto Medium", -16), # font name and size in px
fg_color=None)
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",
command=self.button_event,
fg_color=None,
border_width=2)
fg_color=("gray75", "gray30")) # <- custom tuple-color
self.button_1.grid(row=2, column=0, pady=10, padx=20)
self.button_2 = customtkinter.CTkButton(master=self.frame_left,
text="CTkButton 2",
command=self.button_event,
fg_color=None,
border_width=2)
fg_color=("gray75", "gray30")) # <- custom tuple-color
self.button_2.grid(row=3, column=0, pady=10, padx=20)
self.button_3 = customtkinter.CTkButton(master=self.frame_left,
text="CTkButton 3",
command=self.button_event,
fg_color=None,
border_width=2)
fg_color=("gray75", "gray30")) # <- custom tuple-color
self.button_3.grid(row=4, column=0, pady=10, padx=20)
self.check_box_1 = customtkinter.CTkCheckBox(master=self.frame_left,
@ -86,17 +78,19 @@ class App(customtkinter.CTk):
# ============ frame_right ============
self.frame_right.rowconfigure(0, weight=1)
self.frame_right.rowconfigure(3, weight=1)
for i in [0, 1, 2, 3]:
self.frame_right.rowconfigure(i, weight=1)
self.frame_right.rowconfigure(6, weight=10)
self.frame_right.columnconfigure(0, weight=1)
self.frame_info = customtkinter.CTkFrame(master=self.frame_right,
width=380,
height=200)
self.frame_info.grid(row=0, column=0, columnspan=3, pady=20, padx=20, sticky="wens")
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="wens")
# ============ frame_right -> frame_info ============
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" +
@ -106,52 +100,71 @@ class App(customtkinter.CTk):
height=100,
fg_color=("white", "gray38"), # <- custom tuple-color
justify=tkinter.LEFT)
self.label_info_1.place(relx=0.5, rely=0.15, anchor=tkinter.N)
self.label_info_1.grid(column=0, row=0, sticky="nwe", padx=15, pady=15)
self.progressbar = customtkinter.CTkProgressBar(master=self.frame_info, width=240)
self.progressbar.place(relx=0.5, rely=0.85, anchor=tkinter.S)
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,
fg_color=("white", "gray30"), # <- custom tuple-color
text="CTkRadioButton Group:")
self.label_radio_group.grid(row=0, column=2, columnspan=1, pady=0, padx=20, sticky="wes")
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="")
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="")
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="")
#self.radio_button_1.select()
#self.radio_button_1.deselect()
self.slider_1 = customtkinter.CTkSlider(master=self.frame_right,
from_=1,
to=0,
number_of_steps=3,
command=self.progressbar.set)
self.slider_1.grid(row=1, column=0, columnspan=2, pady=10, padx=20, sticky="we")
self.slider_1.set(0.5)
self.slider_1.grid(row=4, column=0, columnspan=2, pady=10, padx=20, sticky="we")
self.slider_1.set(0.7)
self.slider_2 = customtkinter.CTkSlider(master=self.frame_right,
width=160,
command=self.progressbar.set)
self.slider_2.grid(row=2, column=0, columnspan=2, pady=10, padx=20, sticky="we")
self.slider_2.grid(row=5, column=0, columnspan=2, pady=10, padx=20, sticky="we")
self.slider_2.set(0.7)
self.label_info_2 = customtkinter.CTkLabel(master=self.frame_right,
text="CTkLabel: Lorem ipsum",
fg_color=None,
width=180,
height=20,
justify=tkinter.CENTER)
self.label_info_2.grid(row=1, column=2, columnspan=1, pady=10, padx=20, sticky="we")
self.button_4 = customtkinter.CTkButton(master=self.frame_right,
self.slider_button_1 = customtkinter.CTkButton(master=self.frame_right,
height=25,
text="CTkButton",
command=self.button_event)
self.button_4.grid(row=2, column=2, columnspan=1, pady=10, padx=20, sticky="we")
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.entry = customtkinter.CTkEntry(master=self.frame_right,
width=120,
height=30,
placeholder_text="CTkEntry")
self.entry.grid(row=4, column=0, columnspan=2, pady=20, padx=20, sticky="we")
self.entry.grid(row=7, column=0, columnspan=2, pady=20, padx=20, sticky="we")
self.button_5 = customtkinter.CTkButton(master=self.frame_right,
height=30,
text="CTkButton",
command=self.button_event)
self.button_5.grid(row=4, column=2, columnspan=1, pady=20, padx=20, sticky="we")
self.button_5.grid(row=7, column=2, columnspan=1, pady=20, padx=20, sticky="we")
self.progressbar.set(0.5)