mirror of
https://github.com/TomSchimansky/CustomTkinter.git
synced 2023-08-10 21:13:13 +03:00
fixed CTkDialog
This commit is contained in:
parent
16859991eb
commit
356ed917be
@ -19,7 +19,6 @@ from distutils.version import StrictVersion as Version
|
|||||||
import tkinter
|
import tkinter
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from ctypes import windll, byref, create_unicode_buffer, create_string_buffer
|
|
||||||
|
|
||||||
|
|
||||||
def enable_macos_darkmode():
|
def enable_macos_darkmode():
|
||||||
@ -62,18 +61,21 @@ def set_default_color_theme(color_string):
|
|||||||
CTkColorManager.initialize_color_theme(color_string)
|
CTkColorManager.initialize_color_theme(color_string)
|
||||||
|
|
||||||
|
|
||||||
FR_PRIVATE = 0x10
|
if sys.platform.startswith("win"):
|
||||||
FR_NOT_ENUM = 0x20
|
from ctypes import windll, byref, create_string_buffer
|
||||||
|
|
||||||
|
FR_PRIVATE = 0x10
|
||||||
|
FR_NOT_ENUM = 0x20
|
||||||
|
|
||||||
|
|
||||||
def loadfont(fontpath: str, private=True, enumerable=False):
|
def loadfont(fontpath: str, private=True, enumerable=False):
|
||||||
pathbuf = create_string_buffer(bytes(fontpath, "utf-8"))
|
pathbuf = create_string_buffer(bytes(fontpath, "utf-8"))
|
||||||
add_font_resource_ex = windll.gdi32.AddFontResourceExA
|
add_font_resource_ex = windll.gdi32.AddFontResourceExA
|
||||||
flags = (FR_PRIVATE if private else 0) | (FR_NOT_ENUM if not enumerable else 0)
|
flags = (FR_PRIVATE if private else 0) | (FR_NOT_ENUM if not enumerable else 0)
|
||||||
num_fonts_added = add_font_resource_ex(byref(pathbuf), flags, 0)
|
num_fonts_added = add_font_resource_ex(byref(pathbuf), flags, 0)
|
||||||
return bool(num_fonts_added)
|
return bool(num_fonts_added)
|
||||||
|
|
||||||
|
|
||||||
# load custom font for rendering circles on the tkinter.Canvas with antialiasing
|
# load custom font for rendering circles on the tkinter.Canvas with antialiasing
|
||||||
script_directory = os.path.dirname(os.path.abspath(__file__))
|
script_directory = os.path.dirname(os.path.abspath(__file__))
|
||||||
loadfont(os.path.join(script_directory, "assets", "canvas_shapes_font.otf"), private=True)
|
loadfont(os.path.join(script_directory, "assets", "canvas_shapes_font.otf"), private=True)
|
||||||
|
@ -45,6 +45,7 @@ class CTkDialog:
|
|||||||
self.myLabel = CTkLabel(master=self.label_frame,
|
self.myLabel = CTkLabel(master=self.label_frame,
|
||||||
text=text,
|
text=text,
|
||||||
width=300,
|
width=300,
|
||||||
|
fg_color=None,
|
||||||
height=self.height-100)
|
height=self.height-100)
|
||||||
self.myLabel.place(relx=0.5, rely=0.5, anchor=tkinter.CENTER)
|
self.myLabel.place(relx=0.5, rely=0.5, anchor=tkinter.CENTER)
|
||||||
|
|
||||||
@ -68,7 +69,10 @@ class CTkDialog:
|
|||||||
hover_color=self.hover_color)
|
hover_color=self.hover_color)
|
||||||
self.cancel_button.place(relx=0.72, rely=0.65, anchor=tkinter.CENTER)
|
self.cancel_button.place(relx=0.72, rely=0.65, anchor=tkinter.CENTER)
|
||||||
|
|
||||||
def ok_event(self):
|
self.entry.entry.focus_force()
|
||||||
|
self.entry.bind("<Return>", self.ok_event)
|
||||||
|
|
||||||
|
def ok_event(self, event=None):
|
||||||
self.user_input = self.entry.get()
|
self.user_input = self.entry.get()
|
||||||
self.running = False
|
self.running = False
|
||||||
|
|
||||||
@ -89,14 +93,13 @@ class CTkDialog:
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import customtkinter
|
import customtkinter
|
||||||
customtkinter.enable_macos_darkmode()
|
|
||||||
customtkinter.set_appearance_mode("System")
|
customtkinter.set_appearance_mode("System")
|
||||||
|
|
||||||
app = tkinter.Tk()
|
app = customtkinter.CTk()
|
||||||
app.title("CTkDialog Test")
|
app.title("CTkDialog Test")
|
||||||
|
|
||||||
def button_click_event():
|
def button_click_event():
|
||||||
dialog = CTkDialog(master=None, text="Type in a number:", title="Test", fg_color="green", hover_color="darkgreen")
|
dialog = CTkDialog(master=None, text="Type in a number:", title="Test")
|
||||||
print("Number:", dialog.get_input())
|
print("Number:", dialog.get_input())
|
||||||
|
|
||||||
button = CTkButton(master=app, text="Open Dialog", command=button_click_event)
|
button = CTkButton(master=app, text="Open Dialog", command=button_click_event)
|
||||||
|
@ -4,7 +4,6 @@ import sys
|
|||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
import ctypes
|
import ctypes
|
||||||
import win32con
|
|
||||||
|
|
||||||
from .appearance_mode_tracker import AppearanceModeTracker
|
from .appearance_mode_tracker import AppearanceModeTracker
|
||||||
from .customtkinter_color_manager import CTkColorManager
|
from .customtkinter_color_manager import CTkColorManager
|
||||||
|
Loading…
x
Reference in New Issue
Block a user