mirror of
https://github.com/TomSchimansky/CustomTkinter.git
synced 2023-08-10 21:13:13 +03:00
added state to CTkEntry, completed test for widget state
This commit is contained in:
parent
df1420cd02
commit
eeeb85ec0d
@ -2,7 +2,6 @@ import tkinter
|
||||
|
||||
from .ctk_canvas import CTkCanvas
|
||||
from ..theme_manager import ThemeManager
|
||||
from ..settings import Settings
|
||||
from ..draw_engine import DrawEngine
|
||||
from .widget_base_class import CTkBaseClass
|
||||
|
||||
@ -20,6 +19,7 @@ class CTkEntry(CTkBaseClass):
|
||||
border_color="default_theme",
|
||||
width=120,
|
||||
height=30,
|
||||
state=tkinter.NORMAL,
|
||||
**kwargs):
|
||||
|
||||
# transfer basic functionality (bg_color, size, appearance_mode, scaling) to CTkBaseClass
|
||||
@ -42,6 +42,8 @@ class CTkEntry(CTkBaseClass):
|
||||
self.placeholder_text_active = False
|
||||
self.pre_placeholder_arguments = {} # some set arguments of the entry will be changed for placeholder and then set back
|
||||
|
||||
self.state = state
|
||||
|
||||
self.corner_radius = ThemeManager.theme["shape"]["button_corner_radius"] if corner_radius == "default_theme" else corner_radius
|
||||
self.border_width = ThemeManager.theme["shape"]["entry_border_width"] if border_width == "default_theme" else border_width
|
||||
|
||||
@ -57,6 +59,7 @@ class CTkEntry(CTkBaseClass):
|
||||
width=1,
|
||||
highlightthickness=0,
|
||||
font=self.apply_font_scaling(self.text_font),
|
||||
state=self.state,
|
||||
**kwargs)
|
||||
self.entry.grid(column=0, row=0, sticky="we",
|
||||
padx=self.apply_widget_scaling(self.corner_radius) if self.corner_radius >= 6 else self.apply_widget_scaling(6))
|
||||
@ -138,6 +141,11 @@ class CTkEntry(CTkBaseClass):
|
||||
def configure(self, *args, **kwargs):
|
||||
require_redraw = False # some attribute changes require a call of self.draw() at the end
|
||||
|
||||
if "state" in kwargs:
|
||||
self.state = kwargs["state"]
|
||||
self.entry.configure(state=self.state)
|
||||
del kwargs["state"]
|
||||
|
||||
if "bg_color" in kwargs:
|
||||
if kwargs["bg_color"] is None:
|
||||
self.bg_color = self.detect_color_of_master()
|
||||
|
@ -3,7 +3,7 @@ import customtkinter
|
||||
|
||||
|
||||
root_tk = customtkinter.CTk()
|
||||
root_tk.geometry("400x240")
|
||||
root_tk.geometry("400x800")
|
||||
root_tk.title("CustomTkinter Test")
|
||||
|
||||
|
||||
@ -14,18 +14,34 @@ def change_state(widget):
|
||||
widget.configure(state=tkinter.NORMAL)
|
||||
|
||||
|
||||
def button_2_click():
|
||||
print("button_2 clicked")
|
||||
def widget_click():
|
||||
print("widget clicked")
|
||||
|
||||
|
||||
button_1 = customtkinter.CTkButton(master=root_tk, text="button_1", command=button_2_click)
|
||||
button_1.pack(padx=20, pady=10)
|
||||
button_1 = customtkinter.CTkButton(master=root_tk, text="button_1", command=widget_click)
|
||||
button_1.pack(padx=20, pady=(20, 10))
|
||||
button_2 = customtkinter.CTkButton(master=root_tk, text="Disable/Enable button_1", command=lambda: change_state(button_1))
|
||||
button_2.pack(padx=20, pady=10)
|
||||
button_2.pack(padx=20, pady=(10, 20))
|
||||
|
||||
switch_1 = customtkinter.CTkSwitch(master=root_tk, text="switch_1", command=widget_click)
|
||||
switch_1.pack(padx=20, pady=(20, 10))
|
||||
button_2 = customtkinter.CTkButton(master=root_tk, text="Disable/Enable switch_1", command=lambda: change_state(switch_1))
|
||||
button_2.pack(padx=20, pady=(10, 20))
|
||||
|
||||
entry_1 = customtkinter.CTkEntry(master=root_tk, placeholder_text="entry_1")
|
||||
entry_1.pack(padx=20, pady=(20, 10))
|
||||
button_3 = customtkinter.CTkButton(master=root_tk, text="Disable/Enable entry_1", command=lambda: change_state(entry_1))
|
||||
button_3.pack(padx=20, pady=(10, 20))
|
||||
|
||||
checkbox_1 = customtkinter.CTkCheckBox(master=root_tk, text="checkbox_1")
|
||||
checkbox_1.pack(padx=20, pady=(20, 10))
|
||||
button_4 = customtkinter.CTkButton(master=root_tk, text="Disable/Enable checkbox_1", command=lambda: change_state(checkbox_1))
|
||||
button_4.pack(padx=20, pady=(10, 20))
|
||||
|
||||
radiobutton_1 = customtkinter.CTkRadioButton(master=root_tk, text="radiobutton_1")
|
||||
radiobutton_1.pack(padx=20, pady=(20, 10))
|
||||
button_5 = customtkinter.CTkButton(master=root_tk, text="Disable/Enable entry_1", command=lambda: change_state(radiobutton_1))
|
||||
button_5.pack(padx=20, pady=(10, 20))
|
||||
|
||||
switch_1 = customtkinter.CTkSwitch(master=root_tk, text="switch_1", command=button_2_click)
|
||||
switch_1.pack(padx=20, pady=10)
|
||||
switch_2 = customtkinter.CTkSwitch(master=root_tk, text="Disable/Enable switch_1", command=lambda: change_state(switch_1))
|
||||
switch_2.pack(padx=20, pady=10)
|
||||
|
||||
root_tk.mainloop()
|
||||
|
Loading…
Reference in New Issue
Block a user