added new button grid system, fixed CTkSwitch grid positioning, moved ctk_canvas.py and draw_engine.py to widgets/core_rendering,

This commit is contained in:
Tom Schimansky 2022-10-23 22:33:57 +02:00
parent 90d11e2f3f
commit bf1835922b
23 changed files with 111 additions and 45 deletions

View File

@ -2,16 +2,13 @@ __version__ = "4.6.3"
import os
import sys
from tkinter.constants import *
from tkinter import StringVar, IntVar, DoubleVar, BooleanVar
from tkinter import filedialog
# import manager classes
from .appearance_mode_tracker import AppearanceModeTracker
from .theme_manager import ThemeManager
from .scaling_tracker import ScalingTracker
from .font_manager import FontManager
from .draw_engine import DrawEngine
from .widgets.core_rendering.draw_engine import DrawEngine
AppearanceModeTracker.init_appearance_mode()
@ -45,7 +42,7 @@ if FontManager.load_font(os.path.join(script_directory, "assets", "fonts", "Cust
if DrawEngine.preferred_drawing_method == "font_shapes":
sys.stderr.write("customtkinter.__init__ warning: " +
"Preferred drawing method 'font_shapes' can not be used because the font file could not be loaded.\n" +
"Using 'circle_shapes' instead. The rendering quality will be bad!")
"Using 'circle_shapes' instead. The rendering quality will be bad!\n")
DrawEngine.preferred_drawing_method = "circle_shapes"
# import widgets
@ -58,7 +55,7 @@ from .widgets.ctk_frame import CTkFrame
from .widgets.ctk_progressbar import CTkProgressBar
from .widgets.ctk_label import CTkLabel
from .widgets.ctk_radiobutton import CTkRadioButton
from .widgets.ctk_canvas import CTkCanvas
from .widgets.core_rendering.ctk_canvas import CTkCanvas
from .widgets.ctk_switch import CTkSwitch
from .widgets.ctk_optionmenu import CTkOptionMenu
from .widgets.ctk_combobox import CTkComboBox
@ -67,6 +64,8 @@ from .widgets.ctk_textbox import CTkTextbox
from .widgets.ctk_tabview import CTkTabview
from .widgets.ctk_segmented_button import CTkSegmentedButton
from .widgets.ctk_button_new_grid import CTkButtonNewGrid
# import windows
from .windows.ctk_tk import CTk
from .windows.ctk_toplevel import CTkToplevel

View File

@ -1,6 +1,6 @@
import tkinter
import sys
from typing import Callable, Dict
from typing import Callable
class ScalingTracker:

View File

@ -1,3 +1,3 @@
from .ctk_canvas import CTkCanvas
from customtkinter.widgets.core_rendering.ctk_canvas import CTkCanvas
CTkCanvas.init_font_character_mapping()

View File

@ -5,7 +5,7 @@ import tkinter
from typing import Union, TYPE_CHECKING
if TYPE_CHECKING:
from .widgets.ctk_canvas import CTkCanvas
from customtkinter.widgets.core_rendering.ctk_canvas import CTkCanvas
class DrawEngine:

View File

@ -2,9 +2,9 @@ import tkinter
import sys
from typing import Union, Tuple, Callable
from .ctk_canvas import CTkCanvas
from .core_rendering.ctk_canvas import CTkCanvas
from ..theme_manager import ThemeManager
from ..draw_engine import DrawEngine
from .core_rendering.draw_engine import DrawEngine
from .widget_base_class import CTkBaseClass
from ..utility.ctk_font import CTkFont

View File

@ -2,9 +2,9 @@ import tkinter
import sys
from typing import Union, Tuple, Callable
from .ctk_canvas import CTkCanvas
from .core_rendering.ctk_canvas import CTkCanvas
from ..theme_manager import ThemeManager
from ..draw_engine import DrawEngine
from .core_rendering.draw_engine import DrawEngine
from .widget_base_class import CTkBaseClass
from ..utility.ctk_font import CTkFont

View File

@ -3,9 +3,9 @@ import sys
from typing import Union, Tuple, Callable, List
from .dropdown_menu import DropdownMenu
from .ctk_canvas import CTkCanvas
from .core_rendering.ctk_canvas import CTkCanvas
from ..theme_manager import ThemeManager
from ..draw_engine import DrawEngine
from .core_rendering.draw_engine import DrawEngine
from .widget_base_class import CTkBaseClass
from ..utility.ctk_font import CTkFont

View File

@ -1,9 +1,9 @@
import tkinter
from typing import Union, Tuple
from .ctk_canvas import CTkCanvas
from .core_rendering.ctk_canvas import CTkCanvas
from ..theme_manager import ThemeManager
from ..draw_engine import DrawEngine
from .core_rendering.draw_engine import DrawEngine
from .widget_base_class import CTkBaseClass
from ..utility.ctk_font import CTkFont

View File

@ -1,8 +1,8 @@
from typing import Union, Tuple, List
from .ctk_canvas import CTkCanvas
from .core_rendering.ctk_canvas import CTkCanvas
from ..theme_manager import ThemeManager
from ..draw_engine import DrawEngine
from .core_rendering.draw_engine import DrawEngine
from .widget_base_class import CTkBaseClass

View File

@ -1,9 +1,9 @@
import tkinter
from typing import Union, Tuple, Callable
from .ctk_canvas import CTkCanvas
from .core_rendering.ctk_canvas import CTkCanvas
from ..theme_manager import ThemeManager
from ..draw_engine import DrawEngine
from .core_rendering.draw_engine import DrawEngine
from .widget_base_class import CTkBaseClass
from ..utility.ctk_font import CTkFont

View File

@ -2,9 +2,9 @@ import tkinter
import sys
from typing import Union, Tuple, Callable
from .ctk_canvas import CTkCanvas
from .core_rendering.ctk_canvas import CTkCanvas
from ..theme_manager import ThemeManager
from ..draw_engine import DrawEngine
from .core_rendering.draw_engine import DrawEngine
from .widget_base_class import CTkBaseClass
from .dropdown_menu import DropdownMenu
from ..utility.ctk_font import CTkFont

View File

@ -2,9 +2,9 @@ import tkinter
import math
from typing import Union, Tuple
from .ctk_canvas import CTkCanvas
from .core_rendering.ctk_canvas import CTkCanvas
from ..theme_manager import ThemeManager
from ..draw_engine import DrawEngine
from .core_rendering.draw_engine import DrawEngine
from .widget_base_class import CTkBaseClass

View File

@ -2,9 +2,9 @@ import tkinter
import sys
from typing import Union, Tuple, Callable
from .ctk_canvas import CTkCanvas
from .core_rendering.ctk_canvas import CTkCanvas
from ..theme_manager import ThemeManager
from ..draw_engine import DrawEngine
from .core_rendering.draw_engine import DrawEngine
from .widget_base_class import CTkBaseClass
from ..utility.ctk_font import CTkFont

View File

@ -1,9 +1,9 @@
import sys
from typing import Union, Tuple, Callable
from .ctk_canvas import CTkCanvas
from .core_rendering.ctk_canvas import CTkCanvas
from ..theme_manager import ThemeManager
from ..draw_engine import DrawEngine
from .core_rendering.draw_engine import DrawEngine
from .widget_base_class import CTkBaseClass

View File

@ -2,9 +2,9 @@ import tkinter
import sys
from typing import Union, Tuple, Callable
from .ctk_canvas import CTkCanvas
from .core_rendering.ctk_canvas import CTkCanvas
from ..theme_manager import ThemeManager
from ..draw_engine import DrawEngine
from .core_rendering.draw_engine import DrawEngine
from .widget_base_class import CTkBaseClass

View File

@ -2,9 +2,9 @@ import tkinter
import sys
from typing import Union, Tuple, Callable
from .ctk_canvas import CTkCanvas
from .core_rendering.ctk_canvas import CTkCanvas
from ..theme_manager import ThemeManager
from ..draw_engine import DrawEngine
from .core_rendering.draw_engine import DrawEngine
from .widget_base_class import CTkBaseClass
from ..utility.ctk_font import CTkFont
@ -90,9 +90,9 @@ class CTkSwitch(CTkBaseClass):
self._textvariable = textvariable
# configure grid system (3x1)
self.grid_columnconfigure(0, weight=1)
self.grid_columnconfigure(0, weight=0)
self.grid_columnconfigure(1, weight=0, minsize=self._apply_widget_scaling(6))
self.grid_columnconfigure(2, weight=0)
self.grid_columnconfigure(2, weight=1)
self._bg_canvas = CTkCanvas(master=self,
highlightthickness=0,

View File

@ -4,8 +4,8 @@ from ..theme_manager import ThemeManager
from .ctk_frame import CTkFrame
from .widget_base_class import CTkBaseClass
from .ctk_segmented_button import CTkSegmentedButton
from .ctk_canvas import CTkCanvas
from ..draw_engine import DrawEngine
from .core_rendering.ctk_canvas import CTkCanvas
from .core_rendering.draw_engine import DrawEngine
class CTkTabview(CTkBaseClass):

View File

@ -1,10 +1,10 @@
import tkinter
from typing import Union, Tuple
from .ctk_canvas import CTkCanvas
from .core_rendering.ctk_canvas import CTkCanvas
from .ctk_scrollbar import CTkScrollbar
from ..theme_manager import ThemeManager
from ..draw_engine import DrawEngine
from .core_rendering.draw_engine import DrawEngine
from .widget_base_class import CTkBaseClass
from ..utility.ctk_font import CTkFont

View File

@ -1,7 +1,5 @@
import tkinter
import sys
import copy
import re
from typing import Union, Tuple, Callable, List
from ..theme_manager import ThemeManager

View File

@ -1,10 +1,7 @@
import tkinter
import time
from typing import Union, Tuple
from ..widgets.ctk_label import CTkLabel
from ..widgets.ctk_entry import CTkEntry
from ..widgets.ctk_frame import CTkFrame
from ..windows.ctk_toplevel import CTkToplevel
from ..widgets.ctk_button import CTkButton
from ..appearance_mode_tracker import AppearanceModeTracker

View File

@ -1,3 +1,5 @@
import PIL.ImageTk
import customtkinter
import tkinter
from PIL import Image, ImageTk
@ -31,7 +33,77 @@ class App(customtkinter.CTk):
self.chat_image = self.load_image("/test_images/chat.png", 20)
self.home_image = self.load_image("/test_images/home.png", 20)
self.button_1 = customtkinter.CTkButton(master=self.frame_1, image=self.add_folder_image, text="Add Folder", height=32,
def _pyimagingtkcall(command, photo, id):
tk = photo.tk
try:
tk.call(command, photo, id)
except tkinter.TclError:
print("_pyimagingtkcall error")
class PhotoImage:
def __init__(self, image=None, size=None, **kw):
if hasattr(image, "mode") and hasattr(image, "size"):
# got an image instead of a mode
mode = image.mode
if mode == "P":
# palette mapped data
image.apply_transparency()
image.load()
try:
mode = image.palette.mode
except AttributeError:
mode = "RGB" # default
size = image.size
kw["width"], kw["height"] = size
else:
mode = image
image = None
if mode not in ["1", "L", "RGB", "RGBA"]:
mode = Image.getmodebase(mode)
self.__mode = mode
self.__size = size
self.__photo = tkinter.PhotoImage(**kw)
self.tk = self.__photo.tk
if image:
self.paste(image)
def __del__(self):
name = self.__photo.name
self.__photo.name = None
try:
self.__photo.tk.call("image", "delete", name)
except Exception:
pass # ignore internal errors
def __str__(self):
return str(self.__photo)
def width(self):
return self.__size[0]
def height(self):
return self.__size[1]
def paste(self, im, box=None):
if box is not None:
deprecate("The box parameter", 10, None)
# convert to blittable
im.load()
image = im.im
if image.isblock() and im.mode == self.__mode:
block = image
else:
block = image.new_block(self.__mode, im.size)
image.convert2(block, image) # convert directly between buffers
_pyimagingtkcall("PyImagingPhoto", self.__photo, block.id)
pil_img = Image.open(PATH + "/test_images/add-folder.png").resize((10, 10))
image = PhotoImage(pil_img)
self.button_1 = customtkinter.CTkButton(master=self.frame_1, image=image, text="Add Folder", height=32,
compound="right", command=self.button_function)
self.button_1.grid(row=1, column=0, columnspan=2, padx=20, pady=(20, 10), sticky="ew")