added master kwarg for all widgets and removed *args

This commit is contained in:
Tom Schimansky 2022-10-06 15:53:52 +02:00
parent 4616561c13
commit 63195943b2
21 changed files with 205 additions and 47 deletions

View File

@ -64,6 +64,7 @@ from .widgets.ctk_optionmenu import CTkOptionMenu
from .widgets.ctk_combobox import CTkComboBox from .widgets.ctk_combobox import CTkComboBox
from .widgets.ctk_scrollbar import CTkScrollbar from .widgets.ctk_scrollbar import CTkScrollbar
from .widgets.ctk_textbox import CTkTextbox from .widgets.ctk_textbox import CTkTextbox
from .widgets.ctk_tabview import CTkTabview as _CTkTabview
# import windows # import windows
from .windows.ctk_tk import CTk from .windows.ctk_tk import CTk

View File

@ -35,7 +35,10 @@
"dropdown_hover": ["gray75", "gray28"], "dropdown_hover": ["gray75", "gray28"],
"dropdown_text": ["gray10", "#DCE4EE"], "dropdown_text": ["gray10", "#DCE4EE"],
"scrollbar_button": ["gray55", "gray41"], "scrollbar_button": ["gray55", "gray41"],
"scrollbar_button_hover": ["gray40", "gray53"] "scrollbar_button_hover": ["gray40", "gray53"],
"tabview_button_frame": ["gray70", "gray35"],
"tabview_button": ["gray60", "gray45"],
"tabview_button_hover": ["gray50", "gray55"]
}, },
"text": { "text": {
"macOS": { "macOS": {

View File

@ -15,7 +15,8 @@ class CTkButton(CTkBaseClass):
For detailed information check out the documentation. For detailed information check out the documentation.
""" """
def __init__(self, *args, def __init__(self,
master: any = None,
width: int = 140, width: int = 140,
height: int = 28, height: int = 28,
corner_radius: Union[int, str] = "default_theme", corner_radius: Union[int, str] = "default_theme",
@ -39,7 +40,7 @@ class CTkButton(CTkBaseClass):
**kwargs): **kwargs):
# transfer basic functionality (_bg_color, size, _appearance_mode, scaling) to CTkBaseClass # transfer basic functionality (_bg_color, size, _appearance_mode, scaling) to CTkBaseClass
super().__init__(*args, bg_color=bg_color, width=width, height=height, **kwargs) super().__init__(master=master, bg_color=bg_color, width=width, height=height, **kwargs)
# color # color
self._fg_color = ThemeManager.theme["color"]["button"] if fg_color == "default_theme" else fg_color self._fg_color = ThemeManager.theme["color"]["button"] if fg_color == "default_theme" else fg_color

View File

@ -15,7 +15,8 @@ class CTkCheckBox(CTkBaseClass):
For detailed information check out the documentation. For detailed information check out the documentation.
""" """
def __init__(self, *args, def __init__(self,
master: any = None,
width: int = 24, width: int = 24,
height: int = 24, height: int = 24,
corner_radius: Union[int, str] = "default_theme", corner_radius: Union[int, str] = "default_theme",
@ -41,7 +42,7 @@ class CTkCheckBox(CTkBaseClass):
**kwargs): **kwargs):
# transfer basic functionality (_bg_color, size, _appearance_mode, scaling) to CTkBaseClass # transfer basic functionality (_bg_color, size, _appearance_mode, scaling) to CTkBaseClass
super().__init__(*args, bg_color=bg_color, width=width, height=height, **kwargs) super().__init__(master=master, bg_color=bg_color, width=width, height=height, **kwargs)
# color # color
self._fg_color = ThemeManager.theme["color"]["button"] if fg_color == "default_theme" else fg_color self._fg_color = ThemeManager.theme["color"]["button"] if fg_color == "default_theme" else fg_color

View File

@ -18,7 +18,8 @@ class CTkComboBox(CTkBaseClass):
For detailed information check out the documentation. For detailed information check out the documentation.
""" """
def __init__(self, *args, def __init__(self,
master: any = None,
width: int = 140, width: int = 140,
height: int = 28, height: int = 28,
corner_radius: Union[int, str] = "default_theme", corner_radius: Union[int, str] = "default_theme",
@ -45,7 +46,7 @@ class CTkComboBox(CTkBaseClass):
**kwargs): **kwargs):
# transfer basic functionality (_bg_color, size, _appearance_mode, scaling) to CTkBaseClass # transfer basic functionality (_bg_color, size, _appearance_mode, scaling) to CTkBaseClass
super().__init__(*args, bg_color=bg_color, width=width, height=height, **kwargs) super().__init__(master=master, bg_color=bg_color, width=width, height=height, **kwargs)
# color variables # color variables
self._fg_color = ThemeManager.theme["color"]["entry"] if fg_color == "default_theme" else fg_color self._fg_color = ThemeManager.theme["color"]["entry"] if fg_color == "default_theme" else fg_color

View File

@ -22,7 +22,8 @@ class CTkEntry(CTkBaseClass):
"insertontime", "insertwidth", "justify", "selectborderwidth", "insertontime", "insertwidth", "justify", "selectborderwidth",
"show", "takefocus", "validate", "validatecommand", "xscrollcommand"} "show", "takefocus", "validate", "validatecommand", "xscrollcommand"}
def __init__(self, *args, def __init__(self,
master: any = None,
width: int = 140, width: int = 140,
height: int = 28, height: int = 28,
corner_radius: int = "default_theme", corner_radius: int = "default_theme",
@ -41,10 +42,7 @@ class CTkEntry(CTkBaseClass):
**kwargs): **kwargs):
# transfer basic functionality (bg_color, size, appearance_mode, scaling) to CTkBaseClass # transfer basic functionality (bg_color, size, appearance_mode, scaling) to CTkBaseClass
if "master" in kwargs: super().__init__(master=master, bg_color=bg_color, width=width, height=height)
super().__init__(*args, bg_color=bg_color, width=width, height=height, master=kwargs.pop("master"))
else:
super().__init__(*args, bg_color=bg_color, width=width, height=height)
# configure grid system (1x1) # configure grid system (1x1)
self.grid_rowconfigure(0, weight=1) self.grid_rowconfigure(0, weight=1)

View File

@ -14,7 +14,8 @@ class CTkFrame(CTkBaseClass):
For detailed information check out the documentation. For detailed information check out the documentation.
""" """
def __init__(self, *args, def __init__(self,
master: any = None,
width: int = 200, width: int = 200,
height: int = 200, height: int = 200,
corner_radius: Union[int, str] = "default_theme", corner_radius: Union[int, str] = "default_theme",
@ -28,7 +29,7 @@ class CTkFrame(CTkBaseClass):
**kwargs): **kwargs):
# transfer basic functionality (_bg_color, size, _appearance_mode, scaling) to CTkBaseClass # transfer basic functionality (_bg_color, size, _appearance_mode, scaling) to CTkBaseClass
super().__init__(*args, bg_color=bg_color, width=width, height=height, **kwargs) super().__init__(master=master, bg_color=bg_color, width=width, height=height, **kwargs)
# color # color
self._border_color = ThemeManager.theme["color"]["frame_border"] if border_color == "default_theme" else border_color self._border_color = ThemeManager.theme["color"]["frame_border"] if border_color == "default_theme" else border_color

View File

@ -19,7 +19,8 @@ class CTkLabel(CTkBaseClass):
_valid_tk_label_attributes = {"compound", "cursor", "image", "justify", "padx", "pady", _valid_tk_label_attributes = {"compound", "cursor", "image", "justify", "padx", "pady",
"textvariable", "state", "takefocus", "underline", "wraplength"} "textvariable", "state", "takefocus", "underline", "wraplength"}
def __init__(self, *args, def __init__(self,
master: any = None,
width: int = 140, width: int = 140,
height: int = 28, height: int = 28,
corner_radius: Union[int, str] = "default_theme", corner_radius: Union[int, str] = "default_theme",
@ -34,10 +35,7 @@ class CTkLabel(CTkBaseClass):
**kwargs): **kwargs):
# transfer basic functionality (_bg_color, size, _appearance_mode, scaling) to CTkBaseClass # transfer basic functionality (_bg_color, size, _appearance_mode, scaling) to CTkBaseClass
if "master" in kwargs: super().__init__(master=master, bg_color=bg_color, width=width, height=height)
super().__init__(*args, bg_color=bg_color, width=width, height=height, master=kwargs.pop("master"))
else:
super().__init__(*args, bg_color=bg_color, width=width, height=height)
# color # color
self._fg_color = ThemeManager.theme["color"]["label"] if fg_color == "default_theme" else fg_color self._fg_color = ThemeManager.theme["color"]["label"] if fg_color == "default_theme" else fg_color

View File

@ -16,7 +16,8 @@ class CTkOptionMenu(CTkBaseClass):
For detailed information check out the documentation. For detailed information check out the documentation.
""" """
def __init__(self, *args, def __init__(self,
master: any = None,
width: int = 140, width: int = 140,
height: int = 28, height: int = 28,
corner_radius: Union[int, str] = "default_theme", corner_radius: Union[int, str] = "default_theme",
@ -42,7 +43,7 @@ class CTkOptionMenu(CTkBaseClass):
**kwargs): **kwargs):
# transfer basic functionality (_bg_color, size, _appearance_mode, scaling) to CTkBaseClass # transfer basic functionality (_bg_color, size, _appearance_mode, scaling) to CTkBaseClass
super().__init__(*args, bg_color=bg_color, width=width, height=height, **kwargs) super().__init__(master=master, bg_color=bg_color, width=width, height=height, **kwargs)
# color variables # color variables
self._fg_color = ThemeManager.theme["color"]["button"] if fg_color == "default_theme" else fg_color self._fg_color = ThemeManager.theme["color"]["button"] if fg_color == "default_theme" else fg_color

View File

@ -15,7 +15,8 @@ class CTkProgressBar(CTkBaseClass):
For detailed information check out the documentation. For detailed information check out the documentation.
""" """
def __init__(self, *args, def __init__(self,
master: any = None,
width: Union[int, str] = "default_init", width: Union[int, str] = "default_init",
height: Union[int, str] = "default_init", height: Union[int, str] = "default_init",
corner_radius: Union[str, Tuple[str, str]] = "default_theme", corner_radius: Union[str, Tuple[str, str]] = "default_theme",
@ -46,7 +47,7 @@ class CTkProgressBar(CTkBaseClass):
height = 8 height = 8
# transfer basic functionality (_bg_color, size, _appearance_mode, scaling) to CTkBaseClass # transfer basic functionality (_bg_color, size, _appearance_mode, scaling) to CTkBaseClass
super().__init__(*args, bg_color=bg_color, width=width, height=height, **kwargs) super().__init__(master=master, bg_color=bg_color, width=width, height=height, **kwargs)
# color # color
self._border_color = ThemeManager.theme["color"]["progressbar_border"] if border_color == "default_theme" else border_color self._border_color = ThemeManager.theme["color"]["progressbar_border"] if border_color == "default_theme" else border_color

View File

@ -15,7 +15,8 @@ class CTkRadioButton(CTkBaseClass):
For detailed information check out the documentation. For detailed information check out the documentation.
""" """
def __init__(self, *args, def __init__(self,
master: any = None,
width: int = 22, width: int = 22,
height: int = 22, height: int = 22,
corner_radius: Union[int, str] = "default_theme", corner_radius: Union[int, str] = "default_theme",
@ -40,7 +41,7 @@ class CTkRadioButton(CTkBaseClass):
**kwargs): **kwargs):
# transfer basic functionality (_bg_color, size, _appearance_mode, scaling) to CTkBaseClass # transfer basic functionality (_bg_color, size, _appearance_mode, scaling) to CTkBaseClass
super().__init__(*args, bg_color=bg_color, width=width, height=height, **kwargs) super().__init__(master=master, bg_color=bg_color, width=width, height=height, **kwargs)
# color # color
self._fg_color = ThemeManager.theme["color"]["button"] if fg_color == "default_theme" else fg_color self._fg_color = ThemeManager.theme["color"]["button"] if fg_color == "default_theme" else fg_color

View File

@ -14,7 +14,8 @@ class CTkScrollbar(CTkBaseClass):
For detailed information check out the documentation. For detailed information check out the documentation.
""" """
def __init__(self, *args, def __init__(self,
master: any = None,
width: Union[int, str] = "default_init", width: Union[int, str] = "default_init",
height: Union[int, str] = "default_init", height: Union[int, str] = "default_init",
corner_radius: Union[int, str] = "default_theme", corner_radius: Union[int, str] = "default_theme",
@ -44,7 +45,7 @@ class CTkScrollbar(CTkBaseClass):
height = 200 height = 200
# transfer basic functionality (_bg_color, size, _appearance_mode, scaling) to CTkBaseClass # transfer basic functionality (_bg_color, size, _appearance_mode, scaling) to CTkBaseClass
super().__init__(*args, bg_color=bg_color, width=width, height=height, **kwargs) super().__init__(master=master, bg_color=bg_color, width=width, height=height, **kwargs)
# color # color
self._fg_color = ThemeManager.theme["color"]["frame_high"] if fg_color == "default_theme" else fg_color self._fg_color = ThemeManager.theme["color"]["frame_high"] if fg_color == "default_theme" else fg_color

View File

@ -0,0 +1,19 @@
import tkinter
from typing import Union, Tuple
from .widget_base_class import CTkBaseClass
from .ctk_button import CTkButton
class CTkSegmentedButton(CTkBaseClass):
def __init__(self,
master: any = None,
bg_color: Union[str, Tuple[str, str], None] = None,
fg_color: Union[str, Tuple[str, str], None] = "default_theme",
hover_color: Union[str, Tuple[str, str]] = "default_theme",
text_color: Union[str, Tuple[str, str]] = "default_theme",
text_color_disabled: Union[str, Tuple[str, str]] = "default_theme",
values: list = None):
super().__init__(master=master, )

View File

@ -15,7 +15,8 @@ class CTkSlider(CTkBaseClass):
For detailed information check out the documentation. For detailed information check out the documentation.
""" """
def __init__(self, *args, def __init__(self,
master: any = None,
width: Union[int, str] = "default_init", width: Union[int, str] = "default_init",
height: Union[int, str] = "default_init", height: Union[int, str] = "default_init",
corner_radius: Union[int, str] = "default_theme", corner_radius: Union[int, str] = "default_theme",
@ -52,7 +53,7 @@ class CTkSlider(CTkBaseClass):
height = 16 height = 16
# transfer basic functionality (_bg_color, size, _appearance_mode, scaling) to CTkBaseClass # transfer basic functionality (_bg_color, size, _appearance_mode, scaling) to CTkBaseClass
super().__init__(*args, bg_color=bg_color, width=width, height=height, **kwargs) super().__init__(master=master, bg_color=bg_color, width=width, height=height, **kwargs)
# color # color
self._border_color = border_color self._border_color = border_color

View File

@ -15,7 +15,8 @@ class CTkSwitch(CTkBaseClass):
For detailed information check out the documentation. For detailed information check out the documentation.
""" """
def __init__(self, *args, def __init__(self,
master: any = None,
width: int = 36, width: int = 36,
height: int = 18, height: int = 18,
corner_radius: Union[int, str] = "default_theme", corner_radius: Union[int, str] = "default_theme",
@ -42,7 +43,7 @@ class CTkSwitch(CTkBaseClass):
**kwargs): **kwargs):
# transfer basic functionality (_bg_color, size, _appearance_mode, scaling) to CTkBaseClass # transfer basic functionality (_bg_color, size, _appearance_mode, scaling) to CTkBaseClass
super().__init__(*args, bg_color=bg_color, width=width, height=height, **kwargs) super().__init__(master=master, bg_color=bg_color, width=width, height=height, **kwargs)
# color # color
self._border_color = border_color self._border_color = border_color

View File

@ -1,8 +1,121 @@
import tkinter
from typing import Union, Tuple, List
from ..theme_manager import ThemeManager
from .widget_base_class import CTkBaseClass from .widget_base_class import CTkBaseClass
from .ctk_frame import CTkFrame
class CTkTab:
def __init__(self, master=None, identifier: str = None, text: str = "CTkTab", index: int = 0):
self.text: str = text
self.frame: tkinter.Frame = tkinter.Frame(master, width=0, height=0)
self.identifier = str(id(self.frame)) if identifier is None else identifier
self.visible: bool = True
self.index = index
class CTkTabview(CTkBaseClass): class CTkTabview(CTkBaseClass):
def __init__(self, *args, """
Tabview...
For detailed information check out the documentation.
"""
_top_spacing = 10 # px on top of the buttons
_top_button_overhang = 8 # px
_button_size = 24
def __init__(self,
master: any = None,
width: int = 300,
height: int = 250,
corner_radius: Union[int, str] = "default_theme",
border_width: Union[int, str] = "default_theme",
bg_color: Union[str, Tuple[str, str], None] = None,
fg_color: Union[str, Tuple[str, str], None] = "default_theme",
button_frame_color: Union[str, Tuple[str, str]] = "default_theme",
button_color: Union[str, Tuple[str, str]] = "default_theme",
button_hover_color: Union[str, Tuple[str, str]] = "default_theme",
border_color: Union[str, Tuple[str, str]] = "default_theme",
**kwargs): **kwargs):
super().__init__(*args, **kwargs)
# transfer basic functionality (bg_color, size, appearance_mode, scaling) to CTkBaseClass
super().__init__(master=master, bg_color=bg_color, width=width, height=height, **kwargs)
# determine fg_color
if fg_color == "default_theme":
if isinstance(self.master, (CTkFrame, CTkTabview)):
if self.master.cget("fg_color") == ThemeManager.theme["color"]["frame_low"]:
self._fg_color = ThemeManager.theme["color"]["frame_high"]
else:
self._fg_color = ThemeManager.theme["color"]["frame_low"]
else:
self._fg_color = ThemeManager.theme["color"]["frame_low"]
else:
self._fg_color = fg_color
self._border_color = ThemeManager.theme["color"]["frame_border"] if border_color == "default_theme" else border_color
self._button_frame_color = ThemeManager.theme["color"]["tabview_button_frame"] if button_frame_color == "default_theme" else button_frame_color
self._button_color = ThemeManager.theme["color"]["tabview_button"] if button_color == "default_theme" else button_color
self._button_hover_color = ThemeManager.theme["color"]["tabview_button_hover"] if button_hover_color == "default_theme" else button_hover_color
# shape
self._corner_radius = ThemeManager.theme["shape"]["frame_corner_radius"] if corner_radius == "default_theme" else corner_radius
self._border_width = ThemeManager.theme["shape"]["frame_border_width"] if border_width == "default_theme" else border_width
self._main_frame = CTkFrame(self,
width=width,
height=height - (self._top_spacing + self._top_button_overhang),
bg_color=self._bg_color,
fg_color=self._fg_color,
border_color=self._border_color,
border_width=self._border_width)
self._button_frame = CTkFrame(self,
width=0,
height=0,
bg_color=self._fg_color,
fg_color=self._button_frame_color,
border_color=self._border_color,
border_width=self._border_width)
self._create_grid_for_frames()
self._tab_list: List[CTkTab] = []
def _create_grid_for_frames(self):
""" create 3 x 4 grid system """
self.grid_rowconfigure(0, weight=0, minsize=self._apply_widget_scaling(self._top_spacing))
self.grid_rowconfigure(1, weight=0, minsize=self._apply_widget_scaling(self._top_button_overhang))
self.grid_rowconfigure(2, weight=0, minsize=self._apply_widget_scaling(self._button_size - self._top_button_overhang))
self.grid_rowconfigure(3, weight=1)
self.grid_columnconfigure((0, 2), weight=1, minsize=self._apply_widget_scaling(self._corner_radius))
self.grid_columnconfigure(1, weight=0, minsize=self._apply_widget_scaling(self._corner_radius))
self._main_frame.grid(row=2, column=0, rowspan=2, columnspan=3, sticky="nsew")
self._button_frame.grid(row=1, column=1, rowspan=2, columnspan=1, sticky="nsew")
def _get_tab_by_identifier(self, identifier: str):
for tab in self._tab_list:
if tab.identifier == identifier:
return tab
def create_tab(self, identifier=None, text="CTkTabview"):
new_tab = CTkTab(master=self, identifier=identifier, text=text)
self._tab_list.append(new_tab)
return new_tab.identifier
def select_tab(self, identifier: str):
selected_tab = self._get_tab_by_identifier(identifier)
for tab in self._tab_list:
if tab != selected_tab:
tab.frame.grid_forget()
selected_tab.frame.grid(row=3, column=0, rowspan=1, columnspan=3, sticky="nsew")
def get_tab(self, identifier):
pass pass

View File

@ -31,7 +31,8 @@ class CTkTextbox(CTkBaseClass):
"spacing2", "spacing3", "state", "tabs", "takefocus", "undo", "wrap", "spacing2", "spacing3", "state", "tabs", "takefocus", "undo", "wrap",
"xscrollcommand", "yscrollcommand"} "xscrollcommand", "yscrollcommand"}
def __init__(self, *args, def __init__(self,
master: any = None,
width: int = 200, width: int = 200,
height: int = 200, height: int = 200,
corner_radius: Union[int, str] = "default_theme", corner_radius: Union[int, str] = "default_theme",
@ -50,10 +51,7 @@ class CTkTextbox(CTkBaseClass):
**kwargs): **kwargs):
# transfer basic functionality (_bg_color, size, _appearance_mode, scaling) to CTkBaseClass # transfer basic functionality (_bg_color, size, _appearance_mode, scaling) to CTkBaseClass
if "master" in kwargs: super().__init__(master=master, bg_color=bg_color, width=width, height=height)
super().__init__(*args, bg_color=bg_color, width=width, height=height, master=kwargs.pop("master"))
else:
super().__init__(*args, bg_color=bg_color, width=width, height=height)
# color # color
self._fg_color = ThemeManager.theme["color"]["entry"] if fg_color == "default_theme" else fg_color self._fg_color = ThemeManager.theme["color"]["entry"] if fg_color == "default_theme" else fg_color

View File

@ -23,16 +23,17 @@ class CTkBaseClass(tkinter.Frame):
appearance_mode changes, scaling, bg changes of master if master is not a CTk widget """ appearance_mode changes, scaling, bg changes of master if master is not a CTk widget """
# attributes that are passed to and managed by the tkinter frame only: # attributes that are passed to and managed by the tkinter frame only:
_valid_tk_frame_attributes = {"cursor", "master"} _valid_tk_frame_attributes = {"cursor"}
def __init__(self, *args, def __init__(self,
width: int, master: any = None,
height: int, width: int = 0,
height: int = 0,
bg_color: Union[str, tuple] = None, bg_color: Union[str, tuple] = None,
**kwargs): **kwargs):
super().__init__(*args, width=width, height=height, **pop_from_dict_by_set(kwargs, self._valid_tk_frame_attributes)) super().__init__(master=master, width=width, height=height, **pop_from_dict_by_set(kwargs, self._valid_tk_frame_attributes))
# check if kwargs is empty, if not raise error for unsupported arguments # check if kwargs is empty, if not raise error for unsupported arguments
self._check_kwargs_empty(kwargs, raise_error=True) self._check_kwargs_empty(kwargs, raise_error=True)
@ -231,6 +232,7 @@ class CTkBaseClass(tkinter.Frame):
elif mode_string.lower() == "light": elif mode_string.lower() == "light":
self._appearance_mode = 0 self._appearance_mode = 0
super().configure(bg=ThemeManager.single_color(self._bg_color, self._appearance_mode))
self._draw() self._draw()
def _set_scaling(self, new_widget_scaling, new_spacing_scaling, new_window_scaling): def _set_scaling(self, new_widget_scaling, new_spacing_scaling, new_window_scaling):

View File

@ -49,7 +49,7 @@ class App(customtkinter.CTk):
self.entry = customtkinter.CTkEntry(self, placeholder_text="CTkEntry") self.entry = customtkinter.CTkEntry(self, placeholder_text="CTkEntry")
self.entry.grid(row=3, column=1, columnspan=2, padx=(20, 10), pady=(10, 20), sticky="nsew") self.entry.grid(row=3, column=1, columnspan=2, padx=(20, 10), pady=(10, 20), sticky="nsew")
self.main_button_1 = customtkinter.CTkButton(self, fg_color=None, border_width=2) self.main_button_1 = customtkinter.CTkButton(master=self, fg_color=None, border_width=2)
self.main_button_1.grid(row=3, column=3, padx=(10, 20), pady=(10, 20), sticky="nsew") self.main_button_1.grid(row=3, column=3, padx=(10, 20), pady=(10, 20), sticky="nsew")
self.textbox = customtkinter.CTkTextbox(self) self.textbox = customtkinter.CTkTextbox(self)

View File

@ -0,0 +1,16 @@
import customtkinter
import tkinter.ttk as ttk
app = customtkinter.CTk()
tabview = customtkinter._CTkTabview(app)
tabview.pack(pady=20, padx=20)
tabview.create_tab(identifier="tab1", text="Tab 1")
tabview.select_tab("tab1")
switch = customtkinter.CTkSwitch(app, text="Darkmode", onvalue="dark", offvalue="light",
command=lambda: customtkinter.set_appearance_mode(switch.get()))
switch.pack(padx=20, pady=20)
app.mainloop()

View File

@ -1,8 +1,8 @@
import customtkinter import customtkinter
customtkinter.set_widget_scaling(0.9) #customtkinter.set_widget_scaling(0.9)
customtkinter.set_window_scaling(0.9) #customtkinter.set_window_scaling(0.9)
customtkinter.set_spacing_scaling(0.9) #customtkinter.set_spacing_scaling(0.9)
customtkinter.set_appearance_mode("dark") customtkinter.set_appearance_mode("dark")