mirror of
https://github.com/TomSchimansky/CustomTkinter.git
synced 2023-08-10 21:13:13 +03:00
This commit is contained in:
parent
62b330ddba
commit
cea48c3501
@ -20,6 +20,8 @@ ToDo:
|
||||
- Added .bind() and .focus() methods to almost all widgets
|
||||
- Added 'anchor' option to CTkOptionMenu and 'justify' option to CTkComboBox
|
||||
- Added CTkFont class
|
||||
- Added CTkImage class to replace PIL.ImageTk.PhotoImage, supports scaling and two images for appearance mode, supports configuring
|
||||
|
||||
|
||||
### Changed
|
||||
- Changed 'text_font' attribute to 'font' in all widgets, changed 'dropdown_text_font' to 'dropdown_font'
|
||||
|
@ -12,6 +12,7 @@ from ...ctk_tk import CTk
|
||||
from ...ctk_toplevel import CTkToplevel
|
||||
from ..theme.theme_manager import ThemeManager
|
||||
from ..font.ctk_font import CTkFont
|
||||
from ..image.ctk_image import CTkImage
|
||||
from ..appearance_mode.appearance_mode_base_class import CTkAppearanceModeBaseClass
|
||||
from ..scaling.scaling_base_class import CTkScalingBaseClass
|
||||
|
||||
@ -145,13 +146,13 @@ class CTkBaseClass(tkinter.Frame, CTkAppearanceModeBaseClass, CTkScalingBaseClas
|
||||
else:
|
||||
raise ValueError(f"'{attribute_name}' is not a supported argument. Look at the documentation for supported arguments.")
|
||||
|
||||
@staticmethod
|
||||
def _check_font_type(font: any):
|
||||
def _check_font_type(self, font: any):
|
||||
""" check font type when passed to widget """
|
||||
if isinstance(font, CTkFont):
|
||||
return font
|
||||
|
||||
elif type(font) == tuple and len(font) == 1:
|
||||
sys.stderr.write(f"Warning: font {font} given without size, will be extended with default text size of current theme\n")
|
||||
sys.stderr.write(f"{type(self).__name__} Warning: font {font} given without size, will be extended with default text size of current theme\n")
|
||||
return font[0], ThemeManager.theme["text"]["size"]
|
||||
|
||||
elif type(font) == tuple and 2 <= len(font) <= 3:
|
||||
@ -164,6 +165,17 @@ class CTkBaseClass(tkinter.Frame, CTkAppearanceModeBaseClass, CTkScalingBaseClas
|
||||
f"font=customtkinter.CTkFont(family='<name>', size=<size in px>)\n" +
|
||||
f"font=('<name>', <size in px>)\n")
|
||||
|
||||
def _check_image_type(self, image: any):
|
||||
""" check image type when passed to widget """
|
||||
if image is None:
|
||||
return image
|
||||
elif isinstance(image, CTkImage):
|
||||
return image
|
||||
else:
|
||||
sys.stderr.write(f"{type(self).__name__} Warning: Given image is not CTkImage but {type(image)}. " +
|
||||
f"Image can not be scaled on HighDPI displays, use CTkImage instead.\n")
|
||||
return image
|
||||
|
||||
def _update_dimensions_event(self, event):
|
||||
# only redraw if dimensions changed (for performance), independent of scaling
|
||||
if round(self._current_width) != round(self._reverse_widget_scaling(event.width)) or round(self._current_height) != round(self._reverse_widget_scaling(event.height)):
|
||||
|
@ -70,7 +70,7 @@ class CTkButton(CTkBaseClass):
|
||||
self._border_spacing = border_spacing
|
||||
|
||||
# text, image
|
||||
self._image = image
|
||||
self._image = self._check_image_type(image)
|
||||
self._image_label: Union[tkinter.Label, None] = None
|
||||
self._text = text
|
||||
self._text_label: Union[tkinter.Label, None] = None
|
||||
@ -381,7 +381,7 @@ class CTkButton(CTkBaseClass):
|
||||
if "image" in kwargs:
|
||||
if isinstance(self._image, CTkImage):
|
||||
self._image.remove_configure_callback(self._update_image)
|
||||
self._image = kwargs.pop("image")
|
||||
self._image = self._check_image_type(kwargs.pop("image"))
|
||||
if isinstance(self._image, CTkImage):
|
||||
self._image.add_configure_callback(self._update_image)
|
||||
require_redraw = True
|
||||
|
@ -216,6 +216,14 @@ class CTkCheckBox(CTkBaseClass):
|
||||
self._text_label.configure(bg=self._apply_appearance_mode(self._bg_color))
|
||||
|
||||
def configure(self, require_redraw=False, **kwargs):
|
||||
if "corner_radius" in kwargs:
|
||||
self._corner_radius = kwargs.pop("corner_radius")
|
||||
require_redraw = True
|
||||
|
||||
if "border_width" in kwargs:
|
||||
self._border_width = kwargs.pop("border_width")
|
||||
require_redraw = True
|
||||
|
||||
if "checkbox_width" in kwargs:
|
||||
self._checkbox_width = kwargs.pop("checkbox_width")
|
||||
self._canvas.configure(width=self._apply_widget_scaling(self._checkbox_width))
|
||||
|
@ -23,7 +23,7 @@ class CTkLabel(CTkBaseClass):
|
||||
|
||||
def __init__(self,
|
||||
master: any = None,
|
||||
width: int = 140,
|
||||
width: int = 0,
|
||||
height: int = 28,
|
||||
corner_radius: Union[int, str] = "default_theme",
|
||||
|
||||
@ -53,7 +53,7 @@ class CTkLabel(CTkBaseClass):
|
||||
self._text = text
|
||||
|
||||
# image
|
||||
self._image = image
|
||||
self._image = self._check_image_type(image)
|
||||
self._compound = compound
|
||||
if isinstance(self._image, CTkImage):
|
||||
self._image.add_configure_callback(self._update_image)
|
||||
@ -85,12 +85,9 @@ class CTkLabel(CTkBaseClass):
|
||||
font=self._apply_font_scaling(self._font))
|
||||
self._label.configure(**pop_from_dict_by_set(kwargs, self._valid_tk_label_attributes))
|
||||
|
||||
text_label_grid_sticky = self._anchor if self._anchor != "center" else ""
|
||||
self._label.grid(row=0, column=0, sticky=text_label_grid_sticky,
|
||||
padx=self._apply_widget_scaling(min(self._corner_radius, round(self._current_height/2))))
|
||||
|
||||
check_kwargs_empty(kwargs, raise_error=True)
|
||||
|
||||
self._create_grid()
|
||||
self._update_image()
|
||||
self._draw()
|
||||
|
||||
@ -100,10 +97,7 @@ class CTkLabel(CTkBaseClass):
|
||||
self._canvas.configure(width=self._apply_widget_scaling(self._desired_width), height=self._apply_widget_scaling(self._desired_height))
|
||||
self._label.configure(font=self._apply_font_scaling(self._font))
|
||||
|
||||
text_label_grid_sticky = self._anchor if self._anchor != "center" else ""
|
||||
self._label.grid(row=0, column=0, sticky=text_label_grid_sticky,
|
||||
padx=self._apply_widget_scaling(min(self._corner_radius, round(self._current_height/2))))
|
||||
|
||||
self._create_grid()
|
||||
self._draw(no_color_updates=True)
|
||||
|
||||
def _set_dimensions(self, width=None, height=None):
|
||||
@ -111,6 +105,7 @@ class CTkLabel(CTkBaseClass):
|
||||
|
||||
self._canvas.configure(width=self._apply_widget_scaling(self._desired_width),
|
||||
height=self._apply_widget_scaling(self._desired_height))
|
||||
self._create_grid()
|
||||
self._draw()
|
||||
|
||||
def _update_font(self):
|
||||
@ -134,6 +129,13 @@ class CTkLabel(CTkBaseClass):
|
||||
self._font.remove_size_configure_callback(self._update_font)
|
||||
super().destroy()
|
||||
|
||||
def _create_grid(self):
|
||||
""" configure grid system (1x1) """
|
||||
|
||||
text_label_grid_sticky = self._anchor if self._anchor != "center" else ""
|
||||
self._label.grid(row=0, column=0, sticky=text_label_grid_sticky,
|
||||
padx=self._apply_widget_scaling(min(self._corner_radius, round(self._current_height / 2))))
|
||||
|
||||
def _draw(self, no_color_updates=False):
|
||||
super()._draw(no_color_updates)
|
||||
|
||||
@ -164,15 +166,18 @@ class CTkLabel(CTkBaseClass):
|
||||
self._update_image()
|
||||
|
||||
def configure(self, require_redraw=False, **kwargs):
|
||||
if "anchor" in kwargs:
|
||||
self._anchor = kwargs.pop("anchor")
|
||||
text_label_grid_sticky = self._anchor if self._anchor != "center" else ""
|
||||
self._label.grid(row=0, column=0, sticky=text_label_grid_sticky,
|
||||
padx=self._apply_widget_scaling(min(self._corner_radius, round(self._current_height/2))))
|
||||
if "corner_radius" in kwargs:
|
||||
self._corner_radius = kwargs.pop("corner_radius")
|
||||
self._create_grid()
|
||||
require_redraw = True
|
||||
|
||||
if "compound" in kwargs:
|
||||
self._compound = kwargs.pop("compound")
|
||||
self._label.configure(compound=self._compound)
|
||||
if "fg_color" in kwargs:
|
||||
self._fg_color = kwargs.pop("fg_color")
|
||||
require_redraw = True
|
||||
|
||||
if "text_color" in kwargs:
|
||||
self._text_color = kwargs.pop("text_color")
|
||||
require_redraw = True
|
||||
|
||||
if "text" in kwargs:
|
||||
self._text = kwargs.pop("text")
|
||||
@ -189,25 +194,19 @@ class CTkLabel(CTkBaseClass):
|
||||
if "image" in kwargs:
|
||||
if isinstance(self._image, CTkImage):
|
||||
self._image.remove_configure_callback(self._update_image)
|
||||
self._image = kwargs.pop("image")
|
||||
self._image = self._check_image_type(kwargs.pop("image"))
|
||||
if isinstance(self._image, CTkImage):
|
||||
self._image.add_configure_callback(self._update_image)
|
||||
self._update_image()
|
||||
|
||||
if "fg_color" in kwargs:
|
||||
self._fg_color = kwargs.pop("fg_color")
|
||||
require_redraw = True
|
||||
if "compound" in kwargs:
|
||||
self._compound = kwargs.pop("compound")
|
||||
self._label.configure(compound=self._compound)
|
||||
|
||||
if "text_color" in kwargs:
|
||||
self._text_color = kwargs.pop("text_color")
|
||||
require_redraw = True
|
||||
|
||||
if "corner_radius" in kwargs:
|
||||
self._corner_radius = kwargs.pop("corner_radius")
|
||||
text_label_grid_sticky = self._anchor if self._anchor != "center" else ""
|
||||
self._label.grid(row=0, column=0, sticky=text_label_grid_sticky,
|
||||
padx=self._apply_widget_scaling(min(self._corner_radius, round(self._current_height/2))))
|
||||
require_redraw = True
|
||||
if "anchor" in kwargs:
|
||||
self._anchor = kwargs.pop("anchor")
|
||||
self._label.configure(anchor=self._anchor)
|
||||
self._create_grid()
|
||||
|
||||
self._label.configure(**pop_from_dict_by_set(kwargs, self._valid_tk_label_attributes)) # configure tkinter.Label
|
||||
super().configure(require_redraw=require_redraw, **kwargs) # configure CTkBaseClass
|
||||
|
@ -153,6 +153,14 @@ class CTkProgressBar(CTkBaseClass):
|
||||
outline=self._apply_appearance_mode(self._progress_color))
|
||||
|
||||
def configure(self, require_redraw=False, **kwargs):
|
||||
if "corner_radius" in kwargs:
|
||||
self._corner_radius = kwargs.pop("corner_radius")
|
||||
require_redraw = True
|
||||
|
||||
if "border_width" in kwargs:
|
||||
self._border_width = kwargs.pop("border_width")
|
||||
require_redraw = True
|
||||
|
||||
if "fg_color" in kwargs:
|
||||
self._fg_color = kwargs.pop("fg_color")
|
||||
require_redraw = True
|
||||
@ -165,10 +173,6 @@ class CTkProgressBar(CTkBaseClass):
|
||||
self._progress_color = kwargs.pop("progress_color")
|
||||
require_redraw = True
|
||||
|
||||
if "border_width" in kwargs:
|
||||
self._border_width = kwargs.pop("border_width")
|
||||
require_redraw = True
|
||||
|
||||
if "variable" in kwargs:
|
||||
if self._variable is not None:
|
||||
self._variable.trace_remove("write", self._variable_callback_name)
|
||||
|
@ -58,7 +58,6 @@ class CTkRadioButton(CTkBaseClass):
|
||||
self._corner_radius = ThemeManager.theme["shape"]["radiobutton_corner_radius"] if corner_radius == "default_theme" else corner_radius
|
||||
self._border_width_unchecked = ThemeManager.theme["shape"]["radiobutton_border_width_unchecked"] if border_width_unchecked == "default_theme" else border_width_unchecked
|
||||
self._border_width_checked = ThemeManager.theme["shape"]["radiobutton_border_width_checked"] if border_width_checked == "default_theme" else border_width_checked
|
||||
self._border_width = self._border_width_unchecked
|
||||
|
||||
# text
|
||||
self._text = text
|
||||
@ -165,10 +164,16 @@ class CTkRadioButton(CTkBaseClass):
|
||||
def _draw(self, no_color_updates=False):
|
||||
super()._draw(no_color_updates)
|
||||
|
||||
requires_recoloring = self._draw_engine.draw_rounded_rect_with_border(self._apply_widget_scaling(self._radiobutton_width),
|
||||
self._apply_widget_scaling(self._radiobutton_height),
|
||||
self._apply_widget_scaling(self._corner_radius),
|
||||
self._apply_widget_scaling(self._border_width))
|
||||
if self._check_state is True:
|
||||
requires_recoloring = self._draw_engine.draw_rounded_rect_with_border(self._apply_widget_scaling(self._radiobutton_width),
|
||||
self._apply_widget_scaling(self._radiobutton_height),
|
||||
self._apply_widget_scaling(self._corner_radius),
|
||||
self._apply_widget_scaling(self._border_width_checked))
|
||||
else:
|
||||
requires_recoloring = self._draw_engine.draw_rounded_rect_with_border(self._apply_widget_scaling(self._radiobutton_width),
|
||||
self._apply_widget_scaling(self._radiobutton_height),
|
||||
self._apply_widget_scaling(self._corner_radius),
|
||||
self._apply_widget_scaling(self._border_width_unchecked))
|
||||
|
||||
if no_color_updates is False or requires_recoloring:
|
||||
self._bg_canvas.configure(bg=self._apply_appearance_mode(self._bg_color))
|
||||
@ -195,6 +200,18 @@ class CTkRadioButton(CTkBaseClass):
|
||||
self._text_label.configure(bg=self._apply_appearance_mode(self._bg_color))
|
||||
|
||||
def configure(self, require_redraw=False, **kwargs):
|
||||
if "corner_radius" in kwargs:
|
||||
self._corner_radius = kwargs.pop("corner_radius")
|
||||
require_redraw = True
|
||||
|
||||
if "border_width_unchecked" in kwargs:
|
||||
self._border_width_unchecked = kwargs.pop("border_width_unchecked")
|
||||
require_redraw = True
|
||||
|
||||
if "border_width_checked" in kwargs:
|
||||
self._border_width_checked = kwargs.pop("border_width_checked")
|
||||
require_redraw = True
|
||||
|
||||
if "radiobutton_width" in kwargs:
|
||||
self._radiobutton_width = kwargs.pop("radiobutton_width")
|
||||
self._canvas.configure(width=self._apply_widget_scaling(self._radiobutton_width))
|
||||
@ -239,10 +256,6 @@ class CTkRadioButton(CTkBaseClass):
|
||||
self._border_color = kwargs.pop("border_color")
|
||||
require_redraw = True
|
||||
|
||||
if "border_width" in kwargs:
|
||||
self._border_width = kwargs.pop("border_width")
|
||||
require_redraw = True
|
||||
|
||||
if "hover" in kwargs:
|
||||
self._hover = kwargs.pop("hover")
|
||||
|
||||
@ -365,7 +378,6 @@ class CTkRadioButton(CTkBaseClass):
|
||||
|
||||
def select(self, from_variable_callback=False):
|
||||
self._check_state = True
|
||||
self._border_width = self._border_width_checked
|
||||
self._draw()
|
||||
|
||||
if self._variable is not None and not from_variable_callback:
|
||||
@ -375,7 +387,6 @@ class CTkRadioButton(CTkBaseClass):
|
||||
|
||||
def deselect(self, from_variable_callback=False):
|
||||
self._check_state = False
|
||||
self._border_width = self._border_width_unchecked
|
||||
self._draw()
|
||||
|
||||
if self._variable is not None and not from_variable_callback:
|
||||
|
@ -17,6 +17,7 @@ class CTkTabview(CTkBaseClass):
|
||||
_top_spacing = 10 # px on top of the buttons
|
||||
_top_button_overhang = 8 # px
|
||||
_button_height = 26
|
||||
_segmented_button_border_width = 3
|
||||
|
||||
def __init__(self,
|
||||
master: any = None,
|
||||
@ -67,8 +68,8 @@ class CTkTabview(CTkBaseClass):
|
||||
self._canvas = CTkCanvas(master=self,
|
||||
bg=self._apply_appearance_mode(self._bg_color),
|
||||
highlightthickness=0,
|
||||
width=self._apply_widget_scaling(self._current_width - self._top_spacing - self._top_button_overhang),
|
||||
height=self._apply_widget_scaling(self._current_height))
|
||||
width=self._apply_widget_scaling(self._desired_width),
|
||||
height=self._apply_widget_scaling(self._desired_height - self._top_spacing - self._top_button_overhang))
|
||||
self._draw_engine = DrawEngine(self._canvas)
|
||||
|
||||
self._segmented_button = CTkSegmentedButton(self,
|
||||
@ -82,7 +83,7 @@ class CTkTabview(CTkBaseClass):
|
||||
text_color=text_color,
|
||||
text_color_disabled=text_color_disabled,
|
||||
corner_radius=corner_radius,
|
||||
border_width=self._apply_widget_scaling(3),
|
||||
border_width=self._apply_widget_scaling(self._segmented_button_border_width),
|
||||
command=self._segmented_button_callback,
|
||||
state=state)
|
||||
self._configure_segmented_button_background_corners()
|
||||
@ -143,14 +144,6 @@ class CTkTabview(CTkBaseClass):
|
||||
def _configure_tab_background_corners_by_name(self, name: str):
|
||||
""" needs to be called for changes in fg_color, bg_color, border_width """
|
||||
|
||||
# if self._border_width == 0:
|
||||
# if self._fg_color is not None:
|
||||
# self._tab_dict[name].configure(background_corner_colors=(self._fg_color, self._fg_color, self._bg_color, self._bg_color))
|
||||
# else:
|
||||
# self._tab_dict[name].configure(background_corner_colors=(self._bg_color, self._bg_color, self._bg_color, self._bg_color))
|
||||
# else:
|
||||
# self._tab_dict[name].configure(background_corner_colors=None)
|
||||
|
||||
self._tab_dict[name].configure(background_corner_colors=None)
|
||||
|
||||
def _configure_grid(self):
|
||||
@ -182,6 +175,8 @@ class CTkTabview(CTkBaseClass):
|
||||
|
||||
def _create_tab(self) -> CTkFrame:
|
||||
new_tab = CTkFrame(self,
|
||||
height=0,
|
||||
width=0,
|
||||
fg_color=self._fg_color,
|
||||
border_width=0,
|
||||
corner_radius=self._corner_radius)
|
||||
|
@ -73,8 +73,8 @@ class CTkTextbox(CTkBaseClass):
|
||||
|
||||
self._canvas = CTkCanvas(master=self,
|
||||
highlightthickness=0,
|
||||
width=self._apply_widget_scaling(self._current_width),
|
||||
height=self._apply_widget_scaling(self._current_height))
|
||||
width=self._apply_widget_scaling(self._desired_width),
|
||||
height=self._apply_widget_scaling(self._desired_height))
|
||||
self._canvas.grid(row=0, column=0, rowspan=2, columnspan=2, sticky="nsew")
|
||||
self._canvas.configure(bg=self._apply_appearance_mode(self._bg_color))
|
||||
self._draw_engine = DrawEngine(self._canvas)
|
||||
|
@ -11,11 +11,9 @@ class App(customtkinter.CTk):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
# configure window
|
||||
self.title("CustomTkinter complex_example.py")
|
||||
self.geometry(f"{1100}x{580}")
|
||||
#self.minsize(800, 400)
|
||||
#self.maxsize(1200, 700)
|
||||
self.protocol("WM_DELETE_WINDOW", self.on_closing) # call .on_closing() when app gets closed
|
||||
|
||||
# configure grid layout (4x4)
|
||||
self.grid_columnconfigure(1, weight=1)
|
||||
@ -62,19 +60,20 @@ class App(customtkinter.CTk):
|
||||
self.tabview.add("CTkTabview")
|
||||
self.tabview.add("Tab 2")
|
||||
self.tabview.add("Tab 3")
|
||||
self.tabview.tab("CTkTabview").grid_columnconfigure(0, weight=1) # configure grid of individual tabs
|
||||
self.tabview.tab("Tab 2").grid_columnconfigure(0, weight=1)
|
||||
|
||||
self.tabview.tab("CTkTabview").grid_columnconfigure(0, weight=1)
|
||||
self.optionmenu_1 = customtkinter.CTkOptionMenu(self.tabview.tab("CTkTabview"),
|
||||
dynamic_resizing=False,
|
||||
self.optionmenu_1 = customtkinter.CTkOptionMenu(self.tabview.tab("CTkTabview"), dynamic_resizing=False,
|
||||
values=["Value 1", "Value 2", "Value Long Long Long"])
|
||||
self.optionmenu_1.grid(row=0, column=0, padx=20, pady=(20, 10))
|
||||
self.combobox_1 = customtkinter.CTkComboBox(self.tabview.tab("CTkTabview"),
|
||||
values=["Value 1", "Value 2", "Value Long....."])
|
||||
self.combobox_1.grid(row=1, column=0, padx=20, pady=(10, 10))
|
||||
self.string_input_button = customtkinter.CTkButton(self.tabview.tab("CTkTabview"),
|
||||
text="Open CTkInputDialog",
|
||||
self.string_input_button = customtkinter.CTkButton(self.tabview.tab("CTkTabview"), text="Open CTkInputDialog",
|
||||
command=self.open_input_dialog)
|
||||
self.string_input_button.grid(row=2, column=0, padx=20, pady=(10, 10))
|
||||
self.label_tab_2 = customtkinter.CTkLabel(self.tabview.tab("Tab 2"), text="CTkLabel on Tab 2")
|
||||
self.label_tab_2.grid(row=0, column=0, padx=20, pady=20)
|
||||
|
||||
# create radiobutton frame
|
||||
self.radiobutton_frame = customtkinter.CTkFrame(self)
|
||||
@ -106,10 +105,8 @@ class App(customtkinter.CTk):
|
||||
self.slider_progressbar_frame.grid(row=1, column=1, columnspan=2, padx=(20, 0), pady=(20, 0), sticky="nsew")
|
||||
self.slider_progressbar_frame.grid_columnconfigure(0, weight=1)
|
||||
self.slider_progressbar_frame.grid_rowconfigure(4, weight=1)
|
||||
|
||||
self.seg_button_1 = customtkinter.CTkSegmentedButton(self.slider_progressbar_frame)
|
||||
self.seg_button_1.grid(row=0, column=0, padx=(20, 10), pady=(10, 10), sticky="ew")
|
||||
|
||||
self.progressbar_1 = customtkinter.CTkProgressBar(self.slider_progressbar_frame)
|
||||
self.progressbar_1.grid(row=1, column=0, padx=(20, 10), pady=(10, 10), sticky="ew")
|
||||
self.progressbar_2 = customtkinter.CTkProgressBar(self.slider_progressbar_frame)
|
||||
@ -154,9 +151,6 @@ class App(customtkinter.CTk):
|
||||
def sidebar_button_callback(self):
|
||||
print("sidebar_button click")
|
||||
|
||||
def on_closing(self, event=0):
|
||||
self.destroy()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = App()
|
||||
|
@ -1,13 +1,9 @@
|
||||
import tkinter
|
||||
import tkinter.messagebox
|
||||
import customtkinter
|
||||
from PIL import Image, ImageTk
|
||||
from PIL import Image
|
||||
import os
|
||||
|
||||
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__))
|
||||
customtkinter.set_appearance_mode("dark")
|
||||
|
||||
|
||||
class App(customtkinter.CTk):
|
||||
@ -28,10 +24,11 @@ class App(customtkinter.CTk):
|
||||
self.protocol("WM_DELETE_WINDOW", 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)
|
||||
current_path = os.path.dirname(os.path.realpath(__file__))
|
||||
self.bg_image = customtkinter.CTkImage(Image.open(current_path + "/test_images/bg_gradient.jpg"),
|
||||
size=(self.WIDTH, self.HEIGHT))
|
||||
|
||||
self.image_label = tkinter.Label(master=self, image=self.bg_image)
|
||||
self.image_label = customtkinter.CTkLabel(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,
|
||||
@ -40,7 +37,7 @@ class App(customtkinter.CTk):
|
||||
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,
|
||||
self.label_1 = customtkinter.CTkLabel(master=self.frame, width=200, height=60, corner_radius=6,
|
||||
fg_color=("gray70", "gray25"), text="CustomTkinter\ninterface example")
|
||||
self.label_1.place(relx=0.5, rely=0.3, anchor=tkinter.CENTER)
|
||||
|
||||
|
@ -5,7 +5,7 @@ customtkinter.set_appearance_mode("dark") # Modes: "System" (standard), "Dark",
|
||||
customtkinter.set_default_color_theme("blue") # Themes: "blue" (standard), "green", "dark-blue"
|
||||
|
||||
app = customtkinter.CTk()
|
||||
app.geometry("400x580")
|
||||
app.geometry("400x780")
|
||||
app.title("CustomTkinter simple_example.py")
|
||||
|
||||
|
||||
@ -21,41 +21,53 @@ frame_1 = customtkinter.CTkFrame(master=app)
|
||||
frame_1.pack(pady=20, padx=60, fill="both", expand=True)
|
||||
|
||||
label_1 = customtkinter.CTkLabel(master=frame_1, justify=tkinter.LEFT)
|
||||
label_1.pack(pady=12, padx=10)
|
||||
label_1.pack(pady=10, padx=10)
|
||||
|
||||
progressbar_1 = customtkinter.CTkProgressBar(master=frame_1)
|
||||
progressbar_1.pack(pady=12, padx=10)
|
||||
progressbar_1.pack(pady=10, padx=10)
|
||||
|
||||
button_1 = customtkinter.CTkButton(master=frame_1, command=button_callback)
|
||||
button_1.pack(pady=12, padx=10)
|
||||
button_1.pack(pady=10, padx=10)
|
||||
|
||||
slider_1 = customtkinter.CTkSlider(master=frame_1, command=slider_callback, from_=0, to=1)
|
||||
slider_1.pack(pady=12, padx=10)
|
||||
slider_1.pack(pady=10, padx=10)
|
||||
slider_1.set(0.5)
|
||||
|
||||
entry_1 = customtkinter.CTkEntry(master=frame_1, placeholder_text="CTkEntry")
|
||||
entry_1.pack(pady=12, padx=10)
|
||||
entry_1.pack(pady=10, padx=10)
|
||||
|
||||
optionmenu_1 = customtkinter.CTkOptionMenu(frame_1, values=["Option 1", "Option 2", "Option 42 long long long..."])
|
||||
optionmenu_1.pack(pady=12, padx=10)
|
||||
optionmenu_1.pack(pady=10, padx=10)
|
||||
optionmenu_1.set("CTkOptionMenu")
|
||||
|
||||
combobox_1 = customtkinter.CTkComboBox(frame_1, values=["Option 1", "Option 2", "Option 42 long long long..."])
|
||||
combobox_1.pack(pady=12, padx=10)
|
||||
combobox_1.pack(pady=10, padx=10)
|
||||
optionmenu_1.set("CTkComboBox")
|
||||
|
||||
checkbox_1 = customtkinter.CTkCheckBox(master=frame_1)
|
||||
checkbox_1.pack(pady=12, padx=10)
|
||||
checkbox_1.pack(pady=10, padx=10)
|
||||
|
||||
radiobutton_var = tkinter.IntVar(value=1)
|
||||
|
||||
radiobutton_1 = customtkinter.CTkRadioButton(master=frame_1, variable=radiobutton_var, value=1)
|
||||
radiobutton_1.pack(pady=12, padx=10)
|
||||
radiobutton_1.pack(pady=10, padx=10)
|
||||
|
||||
radiobutton_2 = customtkinter.CTkRadioButton(master=frame_1, variable=radiobutton_var, value=2)
|
||||
radiobutton_2.pack(pady=12, padx=10)
|
||||
radiobutton_2.pack(pady=10, padx=10)
|
||||
|
||||
switch_1 = customtkinter.CTkSwitch(master=frame_1)
|
||||
switch_1.pack(pady=12, padx=10)
|
||||
switch_1.pack(pady=10, padx=10)
|
||||
|
||||
text_1 = customtkinter.CTkTextbox(master=frame_1, width=200, height=70)
|
||||
text_1.pack(pady=10, padx=10)
|
||||
text_1.insert("0.0", "CTkTextbox\n\n\n\n")
|
||||
|
||||
segmented_button_1 = customtkinter.CTkSegmentedButton(master=frame_1, values=["CTkSegmentedButton", "Value 2"])
|
||||
segmented_button_1.pack(pady=10, padx=10)
|
||||
|
||||
tabview_1 = customtkinter.CTkTabview(master=frame_1, width=200, height=70)
|
||||
tabview_1.pack(pady=10, padx=10)
|
||||
tabview_1.add("CTkTabview")
|
||||
tabview_1.add("Tab 2")
|
||||
|
||||
app.mainloop()
|
||||
|
@ -12,6 +12,7 @@ image_2 = customtkinter.CTkImage(light_image=Image.open(file_path + "/test_image
|
||||
size=(30, 50))
|
||||
|
||||
app = customtkinter.CTk()
|
||||
app.geometry("500x900")
|
||||
|
||||
mode_switch = customtkinter.CTkSwitch(app, text="darkmode",
|
||||
command=lambda: customtkinter.set_appearance_mode("dark" if mode_switch.get() == 1 else "light"))
|
||||
@ -24,12 +25,19 @@ scaling_button.pack(padx=20, pady=20)
|
||||
button_1 = customtkinter.CTkButton(app, image=image_1)
|
||||
button_1.pack(padx=20, pady=20)
|
||||
|
||||
button_1 = customtkinter.CTkButton(app, image=image_1, anchor="nw", compound="right", height=50, corner_radius=4)
|
||||
button_1.pack(padx=20, pady=20)
|
||||
|
||||
label_1 = customtkinter.CTkLabel(app, text="", image=image_2, compound="right", fg_color="green", width=0)
|
||||
label_1.pack(padx=20, pady=20)
|
||||
label_1.configure(image=image_1)
|
||||
label_2 = customtkinter.CTkLabel(app, image=ImageTk.PhotoImage(Image.open(file_path + "/test_images/bg_gradient.jpg").resize((100, 100))),
|
||||
text="", compound="right", fg_color="green", width=0)
|
||||
|
||||
label_2 = customtkinter.CTkLabel(app, text="text", image=image_2, compound="right", fg_color="red", width=0, corner_radius=10)
|
||||
label_2.pack(padx=20, pady=20)
|
||||
|
||||
label_3 = customtkinter.CTkLabel(app, image=ImageTk.PhotoImage(Image.open(file_path + "/test_images/bg_gradient.jpg").resize((300, 100))),
|
||||
text="", compound="right", fg_color="green", width=0)
|
||||
label_3.pack(padx=20, pady=20)
|
||||
|
||||
app.mainloop()
|
||||
|
Before Width: | Height: | Size: 7.9 KiB After Width: | Height: | Size: 7.9 KiB |
Before Width: | Height: | Size: 4.8 KiB After Width: | Height: | Size: 4.8 KiB |
Loading…
x
Reference in New Issue
Block a user