mirror of
https://github.com/TomSchimansky/CustomTkinter.git
synced 2023-08-10 21:13:13 +03:00
added text_font configuration for all CTk widgets #266
This commit is contained in:
parent
f39ee5764a
commit
8c9183006c
@ -243,6 +243,11 @@ class CTkButton(CTkBaseClass):
|
||||
else:
|
||||
self.text_label.configure(text=self.text)
|
||||
|
||||
if "text_font" in kwargs:
|
||||
self.text_font = kwargs.pop("text_font")
|
||||
if self.text_label is not None:
|
||||
self.text_label.configure(font=self.apply_font_scaling(self.text_font))
|
||||
|
||||
if "state" in kwargs:
|
||||
self.state = kwargs.pop("state")
|
||||
self.set_cursor()
|
||||
|
@ -177,6 +177,11 @@ class CTkCheckBox(CTkBaseClass):
|
||||
self.text = kwargs.pop("text")
|
||||
self.text_label.configure(text=self.text)
|
||||
|
||||
if "text_font" in kwargs:
|
||||
self.text_font = kwargs.pop("text_font")
|
||||
if self.text_label is not None:
|
||||
self.text_label.configure(font=self.apply_font_scaling(self.text_font))
|
||||
|
||||
if "state" in kwargs:
|
||||
self.state = kwargs.pop("state")
|
||||
self.set_cursor()
|
||||
|
@ -203,6 +203,10 @@ class CTkComboBox(CTkBaseClass):
|
||||
self.text_color = kwargs.pop("text_color")
|
||||
require_redraw = True
|
||||
|
||||
if "text_font" in kwargs:
|
||||
self.text_font = kwargs.pop("text_font")
|
||||
self.entry.configure(font=self.apply_font_scaling(self.text_font))
|
||||
|
||||
if "command" in kwargs:
|
||||
self.command = kwargs.pop("command")
|
||||
|
||||
|
@ -185,6 +185,10 @@ class CTkEntry(CTkBaseClass):
|
||||
self.textvariable = kwargs.pop("textvariable")
|
||||
self.entry.configure(textvariable=self.textvariable)
|
||||
|
||||
if "text_font" in kwargs:
|
||||
self.text_font = kwargs.pop("text_font")
|
||||
self.entry.configure(font=self.apply_font_scaling(self.text_font))
|
||||
|
||||
if "show" in kwargs:
|
||||
if self.placeholder_text_active:
|
||||
self.pre_placeholder_arguments["show"] = kwargs.pop("show")
|
||||
|
@ -123,6 +123,10 @@ class CTkLabel(CTkBaseClass):
|
||||
self.text_label.configure(text=self.text)
|
||||
del kwargs["text"]
|
||||
|
||||
if "text_font" in kwargs:
|
||||
self.text_font = kwargs.pop("text_font")
|
||||
self.text_label.configure(font=self.apply_font_scaling(self.text_font))
|
||||
|
||||
if "fg_color" in kwargs:
|
||||
self.fg_color = kwargs["fg_color"]
|
||||
require_redraw = True
|
||||
|
@ -210,6 +210,10 @@ class CTkOptionMenu(CTkBaseClass):
|
||||
self.text_color = kwargs.pop("text_color")
|
||||
require_redraw = True
|
||||
|
||||
if "text_font" in kwargs:
|
||||
self.text_font = kwargs.pop("text_font")
|
||||
self.text_label.configure(font=self.apply_font_scaling(self.text_font))
|
||||
|
||||
if "command" in kwargs:
|
||||
self.command = kwargs.pop("command")
|
||||
|
||||
@ -245,7 +249,8 @@ class CTkOptionMenu(CTkBaseClass):
|
||||
self.dropdown_menu.configure(text_color=kwargs.pop("dropdown_text_color"))
|
||||
|
||||
if "dropdown_text_font" in kwargs:
|
||||
self.dropdown_menu.configure(text_font=kwargs.pop("dropdown_text_font"))
|
||||
self.dropdown_text_font = kwargs.pop("dropdown_text_font")
|
||||
self.dropdown_menu.configure(text_font=self.dropdown_text_font)
|
||||
|
||||
if "dynamic_resizing" in kwargs:
|
||||
self.dynamic_resizing = kwargs.pop("dynamic_resizing")
|
||||
|
@ -156,6 +156,10 @@ class CTkRadioButton(CTkBaseClass):
|
||||
self.text = kwargs.pop("text")
|
||||
self.text_label.configure(text=self.text)
|
||||
|
||||
if "text_font" in kwargs:
|
||||
self.text_font = kwargs.pop("text_font")
|
||||
self.text_label.configure(font=self.apply_font_scaling(self.text_font))
|
||||
|
||||
if "state" in kwargs:
|
||||
self.state = kwargs.pop("state")
|
||||
self.set_cursor()
|
||||
|
@ -272,6 +272,10 @@ class CTkSwitch(CTkBaseClass):
|
||||
self.text = kwargs.pop("text")
|
||||
self.text_label.configure(text=self.text)
|
||||
|
||||
if "text_font" in kwargs:
|
||||
self.text_font = kwargs.pop("text_font")
|
||||
self.text_label.configure(font=self.apply_font_scaling(self.text_font))
|
||||
|
||||
if "state" in kwargs:
|
||||
self.state = kwargs.pop("state")
|
||||
self.set_cursor()
|
||||
|
@ -161,6 +161,13 @@ class CTkTextbox(CTkBaseClass):
|
||||
if "height" in kwargs:
|
||||
self.set_dimensions(height=kwargs.pop("height"))
|
||||
|
||||
if "text_font" in kwargs:
|
||||
self.text_font = kwargs.pop("text_font")
|
||||
self.textbox.configure(font=self.apply_font_scaling(self.text_font))
|
||||
|
||||
if "font" in kwargs:
|
||||
raise ValueError("No attribute named font. Use text_font instead of font for CTk widgets")
|
||||
|
||||
if "bg_color" in kwargs:
|
||||
super().configure(bg_color=kwargs.pop("bg_color"), require_redraw=require_redraw)
|
||||
else:
|
||||
|
@ -1,71 +0,0 @@
|
||||
import customtkinter
|
||||
import tkinter
|
||||
import sys
|
||||
|
||||
|
||||
class CTkMenu(tkinter.Toplevel):
|
||||
def __init__(self, master, x, y, options):
|
||||
super().__init__()
|
||||
|
||||
self.overrideredirect(True)
|
||||
self.geometry(f"120x{len(options) * (25 + 3) + 3}+{x}+{y}")
|
||||
|
||||
if sys.platform.startswith("darwin"):
|
||||
self.overrideredirect(False)
|
||||
self.wm_attributes("-transparent", True) # turn off shadow
|
||||
self.config(bg='systemTransparent') # transparent bg
|
||||
self.frame = customtkinter.CTkFrame(self, border_width=0, width=120, corner_radius=6, border_color="gray4", fg_color="#333740")
|
||||
elif sys.platform.startswith("win"):
|
||||
self.configure(bg="#FFFFF1")
|
||||
self.wm_attributes("-transparent", "#FFFFF1")
|
||||
self.focus()
|
||||
self.frame = customtkinter.CTkFrame(self, border_width=0, width=120, corner_radius=6, border_color="gray4", fg_color="#333740",
|
||||
overwrite_preferred_drawing_method="circle_shapes")
|
||||
else:
|
||||
self.configure(bg="#FFFFF1")
|
||||
self.wm_attributes("-transparent", "#FFFFF1")
|
||||
self.frame = customtkinter.CTkFrame(self, border_width=0, width=120, corner_radius=6, border_color="gray4", fg_color="#333740",
|
||||
overwrite_preferred_drawing_method="circle_shapes")
|
||||
|
||||
self.frame.grid(row=0, column=0, sticky="nsew", rowspan=len(options) + 1, columnspan=1, ipadx=0, ipady=0)
|
||||
|
||||
self.frame.grid_rowconfigure(len(options) + 1, minsize=3)
|
||||
self.frame.grid_columnconfigure(0, weight=1)
|
||||
self.grid_columnconfigure(0, weight=1)
|
||||
|
||||
self.buttons = []
|
||||
for index, option in enumerate(options):
|
||||
button = customtkinter.CTkButton(self.frame, text=option, height=25, width=108, fg_color="#333740", text_color="gray74",
|
||||
hover_color="gray28", corner_radius=4, command=self.button_click)
|
||||
button.text_label.grid(row=0, column=0, rowspan=2, columnspan=2, sticky="w")
|
||||
button.grid(row=index, column=0, padx=(3, 3), pady=(3, 0), columnspan=1, rowspan=1, sticky="ew")
|
||||
self.buttons.append(button)
|
||||
|
||||
self.bind("<FocusOut>", self.focus_loss_event)
|
||||
self.frame.canvas.bind("<Button-1>", self.focus_loss_event)
|
||||
|
||||
def focus_loss_event(self, event):
|
||||
print("focus loss")
|
||||
self.destroy()
|
||||
# self.update()
|
||||
|
||||
def button_click(self):
|
||||
print("button press")
|
||||
self.destroy()
|
||||
# self.update()
|
||||
|
||||
|
||||
app = customtkinter.CTk()
|
||||
app.geometry("600x500")
|
||||
|
||||
|
||||
def open_menu():
|
||||
menu = CTkMenu(app, button.winfo_rootx(), button.winfo_rooty() + button.winfo_height() + 4, ["Option 1", "Option 2", "Point 3"])
|
||||
|
||||
button = customtkinter.CTkButton(command=open_menu, height=30, corner_radius=6)
|
||||
button.pack(pady=20)
|
||||
|
||||
button_2 = customtkinter.CTkButton(command=open_menu, height=30, corner_radius=6)
|
||||
button_2.pack(pady=60)
|
||||
|
||||
app.mainloop()
|
Loading…
Reference in New Issue
Block a user