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 os
|
||||
import sys
|
||||
from ctypes import windll, byref, create_unicode_buffer, create_string_buffer
|
||||
|
||||
|
||||
def enable_macos_darkmode():
|
||||
@ -62,18 +61,21 @@ def set_default_color_theme(color_string):
|
||||
CTkColorManager.initialize_color_theme(color_string)
|
||||
|
||||
|
||||
FR_PRIVATE = 0x10
|
||||
FR_NOT_ENUM = 0x20
|
||||
if sys.platform.startswith("win"):
|
||||
from ctypes import windll, byref, create_string_buffer
|
||||
|
||||
FR_PRIVATE = 0x10
|
||||
FR_NOT_ENUM = 0x20
|
||||
|
||||
|
||||
def loadfont(fontpath: str, private=True, enumerable=False):
|
||||
pathbuf = create_string_buffer(bytes(fontpath, "utf-8"))
|
||||
add_font_resource_ex = windll.gdi32.AddFontResourceExA
|
||||
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)
|
||||
return bool(num_fonts_added)
|
||||
def loadfont(fontpath: str, private=True, enumerable=False):
|
||||
pathbuf = create_string_buffer(bytes(fontpath, "utf-8"))
|
||||
add_font_resource_ex = windll.gdi32.AddFontResourceExA
|
||||
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)
|
||||
return bool(num_fonts_added)
|
||||
|
||||
|
||||
# load custom font for rendering circles on the tkinter.Canvas with antialiasing
|
||||
script_directory = os.path.dirname(os.path.abspath(__file__))
|
||||
loadfont(os.path.join(script_directory, "assets", "canvas_shapes_font.otf"), private=True)
|
||||
# load custom font for rendering circles on the tkinter.Canvas with antialiasing
|
||||
script_directory = os.path.dirname(os.path.abspath(__file__))
|
||||
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,
|
||||
text=text,
|
||||
width=300,
|
||||
fg_color=None,
|
||||
height=self.height-100)
|
||||
self.myLabel.place(relx=0.5, rely=0.5, anchor=tkinter.CENTER)
|
||||
|
||||
@ -68,7 +69,10 @@ class CTkDialog:
|
||||
hover_color=self.hover_color)
|
||||
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.running = False
|
||||
|
||||
@ -89,14 +93,13 @@ class CTkDialog:
|
||||
|
||||
if __name__ == "__main__":
|
||||
import customtkinter
|
||||
customtkinter.enable_macos_darkmode()
|
||||
customtkinter.set_appearance_mode("System")
|
||||
|
||||
app = tkinter.Tk()
|
||||
app = customtkinter.CTk()
|
||||
app.title("CTkDialog Test")
|
||||
|
||||
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())
|
||||
|
||||
button = CTkButton(master=app, text="Open Dialog", command=button_click_event)
|
||||
|
@ -4,7 +4,6 @@ import sys
|
||||
import os
|
||||
import platform
|
||||
import ctypes
|
||||
import win32con
|
||||
|
||||
from .appearance_mode_tracker import AppearanceModeTracker
|
||||
from .customtkinter_color_manager import CTkColorManager
|
||||
|
Loading…
x
Reference in New Issue
Block a user