mirror of
https://github.com/TomSchimansky/CustomTkinter.git
synced 2023-08-10 21:13:13 +03:00
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:
parent
90d11e2f3f
commit
bf1835922b
@ -2,16 +2,13 @@ __version__ = "4.6.3"
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from tkinter.constants import *
|
|
||||||
from tkinter import StringVar, IntVar, DoubleVar, BooleanVar
|
|
||||||
from tkinter import filedialog
|
|
||||||
|
|
||||||
# import manager classes
|
# import manager classes
|
||||||
from .appearance_mode_tracker import AppearanceModeTracker
|
from .appearance_mode_tracker import AppearanceModeTracker
|
||||||
from .theme_manager import ThemeManager
|
from .theme_manager import ThemeManager
|
||||||
from .scaling_tracker import ScalingTracker
|
from .scaling_tracker import ScalingTracker
|
||||||
from .font_manager import FontManager
|
from .font_manager import FontManager
|
||||||
from .draw_engine import DrawEngine
|
from .widgets.core_rendering.draw_engine import DrawEngine
|
||||||
|
|
||||||
AppearanceModeTracker.init_appearance_mode()
|
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":
|
if DrawEngine.preferred_drawing_method == "font_shapes":
|
||||||
sys.stderr.write("customtkinter.__init__ warning: " +
|
sys.stderr.write("customtkinter.__init__ warning: " +
|
||||||
"Preferred drawing method 'font_shapes' can not be used because the font file could not be loaded.\n" +
|
"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"
|
DrawEngine.preferred_drawing_method = "circle_shapes"
|
||||||
|
|
||||||
# import widgets
|
# import widgets
|
||||||
@ -58,7 +55,7 @@ from .widgets.ctk_frame import CTkFrame
|
|||||||
from .widgets.ctk_progressbar import CTkProgressBar
|
from .widgets.ctk_progressbar import CTkProgressBar
|
||||||
from .widgets.ctk_label import CTkLabel
|
from .widgets.ctk_label import CTkLabel
|
||||||
from .widgets.ctk_radiobutton import CTkRadioButton
|
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_switch import CTkSwitch
|
||||||
from .widgets.ctk_optionmenu import CTkOptionMenu
|
from .widgets.ctk_optionmenu import CTkOptionMenu
|
||||||
from .widgets.ctk_combobox import CTkComboBox
|
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_tabview import CTkTabview
|
||||||
from .widgets.ctk_segmented_button import CTkSegmentedButton
|
from .widgets.ctk_segmented_button import CTkSegmentedButton
|
||||||
|
|
||||||
|
from .widgets.ctk_button_new_grid import CTkButtonNewGrid
|
||||||
|
|
||||||
# import windows
|
# import windows
|
||||||
from .windows.ctk_tk import CTk
|
from .windows.ctk_tk import CTk
|
||||||
from .windows.ctk_toplevel import CTkToplevel
|
from .windows.ctk_toplevel import CTkToplevel
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import tkinter
|
import tkinter
|
||||||
import sys
|
import sys
|
||||||
from typing import Callable, Dict
|
from typing import Callable
|
||||||
|
|
||||||
|
|
||||||
class ScalingTracker:
|
class ScalingTracker:
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
from .ctk_canvas import CTkCanvas
|
from customtkinter.widgets.core_rendering.ctk_canvas import CTkCanvas
|
||||||
|
|
||||||
CTkCanvas.init_font_character_mapping()
|
CTkCanvas.init_font_character_mapping()
|
||||||
|
0
customtkinter/widgets/core_rendering/__init__.py
Normal file
0
customtkinter/widgets/core_rendering/__init__.py
Normal file
@ -5,7 +5,7 @@ import tkinter
|
|||||||
from typing import Union, TYPE_CHECKING
|
from typing import Union, TYPE_CHECKING
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from .widgets.ctk_canvas import CTkCanvas
|
from customtkinter.widgets.core_rendering.ctk_canvas import CTkCanvas
|
||||||
|
|
||||||
|
|
||||||
class DrawEngine:
|
class DrawEngine:
|
@ -2,9 +2,9 @@ import tkinter
|
|||||||
import sys
|
import sys
|
||||||
from typing import Union, Tuple, Callable
|
from typing import Union, Tuple, Callable
|
||||||
|
|
||||||
from .ctk_canvas import CTkCanvas
|
from .core_rendering.ctk_canvas import CTkCanvas
|
||||||
from ..theme_manager import ThemeManager
|
from ..theme_manager import ThemeManager
|
||||||
from ..draw_engine import DrawEngine
|
from .core_rendering.draw_engine import DrawEngine
|
||||||
from .widget_base_class import CTkBaseClass
|
from .widget_base_class import CTkBaseClass
|
||||||
from ..utility.ctk_font import CTkFont
|
from ..utility.ctk_font import CTkFont
|
||||||
|
|
||||||
|
@ -2,9 +2,9 @@ import tkinter
|
|||||||
import sys
|
import sys
|
||||||
from typing import Union, Tuple, Callable
|
from typing import Union, Tuple, Callable
|
||||||
|
|
||||||
from .ctk_canvas import CTkCanvas
|
from .core_rendering.ctk_canvas import CTkCanvas
|
||||||
from ..theme_manager import ThemeManager
|
from ..theme_manager import ThemeManager
|
||||||
from ..draw_engine import DrawEngine
|
from .core_rendering.draw_engine import DrawEngine
|
||||||
from .widget_base_class import CTkBaseClass
|
from .widget_base_class import CTkBaseClass
|
||||||
from ..utility.ctk_font import CTkFont
|
from ..utility.ctk_font import CTkFont
|
||||||
|
|
||||||
|
@ -3,9 +3,9 @@ import sys
|
|||||||
from typing import Union, Tuple, Callable, List
|
from typing import Union, Tuple, Callable, List
|
||||||
|
|
||||||
from .dropdown_menu import DropdownMenu
|
from .dropdown_menu import DropdownMenu
|
||||||
from .ctk_canvas import CTkCanvas
|
from .core_rendering.ctk_canvas import CTkCanvas
|
||||||
from ..theme_manager import ThemeManager
|
from ..theme_manager import ThemeManager
|
||||||
from ..draw_engine import DrawEngine
|
from .core_rendering.draw_engine import DrawEngine
|
||||||
from .widget_base_class import CTkBaseClass
|
from .widget_base_class import CTkBaseClass
|
||||||
from ..utility.ctk_font import CTkFont
|
from ..utility.ctk_font import CTkFont
|
||||||
|
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import tkinter
|
import tkinter
|
||||||
from typing import Union, Tuple
|
from typing import Union, Tuple
|
||||||
|
|
||||||
from .ctk_canvas import CTkCanvas
|
from .core_rendering.ctk_canvas import CTkCanvas
|
||||||
from ..theme_manager import ThemeManager
|
from ..theme_manager import ThemeManager
|
||||||
from ..draw_engine import DrawEngine
|
from .core_rendering.draw_engine import DrawEngine
|
||||||
from .widget_base_class import CTkBaseClass
|
from .widget_base_class import CTkBaseClass
|
||||||
from ..utility.ctk_font import CTkFont
|
from ..utility.ctk_font import CTkFont
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
from typing import Union, Tuple, List
|
from typing import Union, Tuple, List
|
||||||
|
|
||||||
from .ctk_canvas import CTkCanvas
|
from .core_rendering.ctk_canvas import CTkCanvas
|
||||||
from ..theme_manager import ThemeManager
|
from ..theme_manager import ThemeManager
|
||||||
from ..draw_engine import DrawEngine
|
from .core_rendering.draw_engine import DrawEngine
|
||||||
from .widget_base_class import CTkBaseClass
|
from .widget_base_class import CTkBaseClass
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import tkinter
|
import tkinter
|
||||||
from typing import Union, Tuple, Callable
|
from typing import Union, Tuple, Callable
|
||||||
|
|
||||||
from .ctk_canvas import CTkCanvas
|
from .core_rendering.ctk_canvas import CTkCanvas
|
||||||
from ..theme_manager import ThemeManager
|
from ..theme_manager import ThemeManager
|
||||||
from ..draw_engine import DrawEngine
|
from .core_rendering.draw_engine import DrawEngine
|
||||||
from .widget_base_class import CTkBaseClass
|
from .widget_base_class import CTkBaseClass
|
||||||
from ..utility.ctk_font import CTkFont
|
from ..utility.ctk_font import CTkFont
|
||||||
|
|
||||||
|
@ -2,9 +2,9 @@ import tkinter
|
|||||||
import sys
|
import sys
|
||||||
from typing import Union, Tuple, Callable
|
from typing import Union, Tuple, Callable
|
||||||
|
|
||||||
from .ctk_canvas import CTkCanvas
|
from .core_rendering.ctk_canvas import CTkCanvas
|
||||||
from ..theme_manager import ThemeManager
|
from ..theme_manager import ThemeManager
|
||||||
from ..draw_engine import DrawEngine
|
from .core_rendering.draw_engine import DrawEngine
|
||||||
from .widget_base_class import CTkBaseClass
|
from .widget_base_class import CTkBaseClass
|
||||||
from .dropdown_menu import DropdownMenu
|
from .dropdown_menu import DropdownMenu
|
||||||
from ..utility.ctk_font import CTkFont
|
from ..utility.ctk_font import CTkFont
|
||||||
|
@ -2,9 +2,9 @@ import tkinter
|
|||||||
import math
|
import math
|
||||||
from typing import Union, Tuple
|
from typing import Union, Tuple
|
||||||
|
|
||||||
from .ctk_canvas import CTkCanvas
|
from .core_rendering.ctk_canvas import CTkCanvas
|
||||||
from ..theme_manager import ThemeManager
|
from ..theme_manager import ThemeManager
|
||||||
from ..draw_engine import DrawEngine
|
from .core_rendering.draw_engine import DrawEngine
|
||||||
from .widget_base_class import CTkBaseClass
|
from .widget_base_class import CTkBaseClass
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,9 +2,9 @@ import tkinter
|
|||||||
import sys
|
import sys
|
||||||
from typing import Union, Tuple, Callable
|
from typing import Union, Tuple, Callable
|
||||||
|
|
||||||
from .ctk_canvas import CTkCanvas
|
from .core_rendering.ctk_canvas import CTkCanvas
|
||||||
from ..theme_manager import ThemeManager
|
from ..theme_manager import ThemeManager
|
||||||
from ..draw_engine import DrawEngine
|
from .core_rendering.draw_engine import DrawEngine
|
||||||
from .widget_base_class import CTkBaseClass
|
from .widget_base_class import CTkBaseClass
|
||||||
from ..utility.ctk_font import CTkFont
|
from ..utility.ctk_font import CTkFont
|
||||||
|
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import sys
|
import sys
|
||||||
from typing import Union, Tuple, Callable
|
from typing import Union, Tuple, Callable
|
||||||
|
|
||||||
from .ctk_canvas import CTkCanvas
|
from .core_rendering.ctk_canvas import CTkCanvas
|
||||||
from ..theme_manager import ThemeManager
|
from ..theme_manager import ThemeManager
|
||||||
from ..draw_engine import DrawEngine
|
from .core_rendering.draw_engine import DrawEngine
|
||||||
from .widget_base_class import CTkBaseClass
|
from .widget_base_class import CTkBaseClass
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,9 +2,9 @@ import tkinter
|
|||||||
import sys
|
import sys
|
||||||
from typing import Union, Tuple, Callable
|
from typing import Union, Tuple, Callable
|
||||||
|
|
||||||
from .ctk_canvas import CTkCanvas
|
from .core_rendering.ctk_canvas import CTkCanvas
|
||||||
from ..theme_manager import ThemeManager
|
from ..theme_manager import ThemeManager
|
||||||
from ..draw_engine import DrawEngine
|
from .core_rendering.draw_engine import DrawEngine
|
||||||
from .widget_base_class import CTkBaseClass
|
from .widget_base_class import CTkBaseClass
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,9 +2,9 @@ import tkinter
|
|||||||
import sys
|
import sys
|
||||||
from typing import Union, Tuple, Callable
|
from typing import Union, Tuple, Callable
|
||||||
|
|
||||||
from .ctk_canvas import CTkCanvas
|
from .core_rendering.ctk_canvas import CTkCanvas
|
||||||
from ..theme_manager import ThemeManager
|
from ..theme_manager import ThemeManager
|
||||||
from ..draw_engine import DrawEngine
|
from .core_rendering.draw_engine import DrawEngine
|
||||||
from .widget_base_class import CTkBaseClass
|
from .widget_base_class import CTkBaseClass
|
||||||
from ..utility.ctk_font import CTkFont
|
from ..utility.ctk_font import CTkFont
|
||||||
|
|
||||||
@ -90,9 +90,9 @@ class CTkSwitch(CTkBaseClass):
|
|||||||
self._textvariable = textvariable
|
self._textvariable = textvariable
|
||||||
|
|
||||||
# configure grid system (3x1)
|
# 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(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,
|
self._bg_canvas = CTkCanvas(master=self,
|
||||||
highlightthickness=0,
|
highlightthickness=0,
|
||||||
|
@ -4,8 +4,8 @@ from ..theme_manager import ThemeManager
|
|||||||
from .ctk_frame import CTkFrame
|
from .ctk_frame import CTkFrame
|
||||||
from .widget_base_class import CTkBaseClass
|
from .widget_base_class import CTkBaseClass
|
||||||
from .ctk_segmented_button import CTkSegmentedButton
|
from .ctk_segmented_button import CTkSegmentedButton
|
||||||
from .ctk_canvas import CTkCanvas
|
from .core_rendering.ctk_canvas import CTkCanvas
|
||||||
from ..draw_engine import DrawEngine
|
from .core_rendering.draw_engine import DrawEngine
|
||||||
|
|
||||||
|
|
||||||
class CTkTabview(CTkBaseClass):
|
class CTkTabview(CTkBaseClass):
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import tkinter
|
import tkinter
|
||||||
from typing import Union, Tuple
|
from typing import Union, Tuple
|
||||||
|
|
||||||
from .ctk_canvas import CTkCanvas
|
from .core_rendering.ctk_canvas import CTkCanvas
|
||||||
from .ctk_scrollbar import CTkScrollbar
|
from .ctk_scrollbar import CTkScrollbar
|
||||||
from ..theme_manager import ThemeManager
|
from ..theme_manager import ThemeManager
|
||||||
from ..draw_engine import DrawEngine
|
from .core_rendering.draw_engine import DrawEngine
|
||||||
from .widget_base_class import CTkBaseClass
|
from .widget_base_class import CTkBaseClass
|
||||||
from ..utility.ctk_font import CTkFont
|
from ..utility.ctk_font import CTkFont
|
||||||
|
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
import tkinter
|
import tkinter
|
||||||
import sys
|
import sys
|
||||||
import copy
|
|
||||||
import re
|
|
||||||
from typing import Union, Tuple, Callable, List
|
from typing import Union, Tuple, Callable, List
|
||||||
|
|
||||||
from ..theme_manager import ThemeManager
|
from ..theme_manager import ThemeManager
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
import tkinter
|
|
||||||
import time
|
|
||||||
from typing import Union, Tuple
|
from typing import Union, Tuple
|
||||||
|
|
||||||
from ..widgets.ctk_label import CTkLabel
|
from ..widgets.ctk_label import CTkLabel
|
||||||
from ..widgets.ctk_entry import CTkEntry
|
from ..widgets.ctk_entry import CTkEntry
|
||||||
from ..widgets.ctk_frame import CTkFrame
|
|
||||||
from ..windows.ctk_toplevel import CTkToplevel
|
from ..windows.ctk_toplevel import CTkToplevel
|
||||||
from ..widgets.ctk_button import CTkButton
|
from ..widgets.ctk_button import CTkButton
|
||||||
from ..appearance_mode_tracker import AppearanceModeTracker
|
from ..appearance_mode_tracker import AppearanceModeTracker
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import PIL.ImageTk
|
||||||
|
|
||||||
import customtkinter
|
import customtkinter
|
||||||
import tkinter
|
import tkinter
|
||||||
from PIL import Image, ImageTk
|
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.chat_image = self.load_image("/test_images/chat.png", 20)
|
||||||
self.home_image = self.load_image("/test_images/home.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)
|
compound="right", command=self.button_function)
|
||||||
self.button_1.grid(row=1, column=0, columnspan=2, padx=20, pady=(20, 10), sticky="ew")
|
self.button_1.grid(row=1, column=0, columnspan=2, padx=20, pady=(20, 10), sticky="ew")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user