mirror of
https://github.com/TomSchimansky/CustomTkinter.git
synced 2023-08-10 21:13:13 +03:00
Readme added gif
This commit is contained in:
parent
e2b2db08df
commit
7f67c833fb
@ -72,6 +72,11 @@ which gives the following with the above simple button program:
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
If you set the appearance mode to "System", it should change with
|
||||||
|
the System mode:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
### Advanced example with multiple CTkFrames
|
### Advanced example with multiple CTkFrames
|
||||||
|
|
||||||
Here I used the ``customtkinter.enable_macos_darkmode()`` command to
|
Here I used the ``customtkinter.enable_macos_darkmode()`` command to
|
||||||
|
@ -4,6 +4,7 @@ from .customtkinter_frame import CTkFrame
|
|||||||
from .customtkinter_progressbar import CTkProgressBar
|
from .customtkinter_progressbar import CTkProgressBar
|
||||||
from .customtkinter_label import CTkLabel
|
from .customtkinter_label import CTkLabel
|
||||||
from .customtkinter_entry import CTkEntry
|
from .customtkinter_entry import CTkEntry
|
||||||
|
from .customtkinter_dialog import CTkDialog
|
||||||
|
|
||||||
from .appearance_mode_tracker import AppearanceModeTracker, SystemAppearanceModeListenerNoThread
|
from .appearance_mode_tracker import AppearanceModeTracker, SystemAppearanceModeListenerNoThread
|
||||||
from .customtkinter_color_manager import CTkColorManager
|
from .customtkinter_color_manager import CTkColorManager
|
||||||
|
@ -248,7 +248,7 @@ class CTkButton(tkinter.Frame):
|
|||||||
def set_text(self, text):
|
def set_text(self, text):
|
||||||
self.text = text
|
self.text = text
|
||||||
if self.text_label is not None:
|
if self.text_label is not None:
|
||||||
self.text_label.configure(text=self.text)
|
self.text_label.configure(text=self.text, width=len(self.text))
|
||||||
else:
|
else:
|
||||||
sys.stderr.write("ERROR (CTkButton): Cant change text because button has no text.")
|
sys.stderr.write("ERROR (CTkButton): Cant change text because button has no text.")
|
||||||
|
|
||||||
|
100
customtkinter/customtkinter_dialog.py
Normal file
100
customtkinter/customtkinter_dialog.py
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
import tkinter
|
||||||
|
import time
|
||||||
|
|
||||||
|
from customtkinter.customtkinter_label import CTkLabel
|
||||||
|
from customtkinter.customtkinter_button import CTkButton
|
||||||
|
from customtkinter.customtkinter_entry import CTkEntry
|
||||||
|
from customtkinter.customtkinter_color_manager import CTkColorManager
|
||||||
|
|
||||||
|
|
||||||
|
class CTkDialog:
|
||||||
|
def __init__(self,
|
||||||
|
master=None,
|
||||||
|
title="CTkDialog",
|
||||||
|
text="CTkDialog",
|
||||||
|
fg_color=CTkColorManager.MAIN,
|
||||||
|
hover_color=CTkColorManager.MAIN_HOVER):
|
||||||
|
self.master = master
|
||||||
|
|
||||||
|
self.user_input = None
|
||||||
|
self.running = False
|
||||||
|
|
||||||
|
self.height = len(text.split("\n"))*20 + 150
|
||||||
|
self.fg_color = fg_color
|
||||||
|
self.hover_color = hover_color
|
||||||
|
|
||||||
|
self.top = tkinter.Toplevel()
|
||||||
|
self.top.geometry("300x{}".format(self.height))
|
||||||
|
self.top.resizable(False, False)
|
||||||
|
self.top.title(title)
|
||||||
|
|
||||||
|
self.label_frame = tkinter.Frame(master=self.top,
|
||||||
|
width=300,
|
||||||
|
height=self.height-100)
|
||||||
|
self.label_frame.place(relx=0.5, rely=0, anchor=tkinter.N)
|
||||||
|
|
||||||
|
self.button_and_entry_frame = tkinter.Frame(master=self.top,
|
||||||
|
width=300,
|
||||||
|
height=100)
|
||||||
|
self.button_and_entry_frame.place(relx=0.5, rely=1, anchor=tkinter.S)
|
||||||
|
|
||||||
|
self.myLabel = CTkLabel(master=self.label_frame,
|
||||||
|
text=text,
|
||||||
|
width=300,
|
||||||
|
height=self.height-100)
|
||||||
|
self.myLabel.place(relx=0.5, rely=0.5, anchor=tkinter.CENTER)
|
||||||
|
|
||||||
|
self.entry = CTkEntry(master=self.button_and_entry_frame,
|
||||||
|
width=180)
|
||||||
|
self.entry.place(relx=0.5, rely=0.15, anchor=tkinter.CENTER)
|
||||||
|
|
||||||
|
self.ok_button = CTkButton(master=self.button_and_entry_frame,
|
||||||
|
text='Ok',
|
||||||
|
command=self.ok_event,
|
||||||
|
fg_color=self.fg_color,
|
||||||
|
hover_color=self.hover_color)
|
||||||
|
self.ok_button.place(relx=0.25, rely=0.75, anchor=tkinter.CENTER)
|
||||||
|
|
||||||
|
self.cancel_button = CTkButton(master=self.button_and_entry_frame,
|
||||||
|
text='Cancel',
|
||||||
|
command=self.cancel_event,
|
||||||
|
fg_color=self.fg_color,
|
||||||
|
hover_color=self.hover_color)
|
||||||
|
self.cancel_button.place(relx=0.75, rely=0.75, anchor=tkinter.CENTER)
|
||||||
|
|
||||||
|
def ok_event(self):
|
||||||
|
self.user_input = self.entry.get()
|
||||||
|
self.running = False
|
||||||
|
|
||||||
|
def cancel_event(self):
|
||||||
|
self.running = False
|
||||||
|
|
||||||
|
def get_input(self):
|
||||||
|
self.running = True
|
||||||
|
|
||||||
|
while self.running:
|
||||||
|
self.top.update()
|
||||||
|
time.sleep(0.01)
|
||||||
|
|
||||||
|
time.sleep(0.05)
|
||||||
|
self.top.destroy()
|
||||||
|
return self.user_input
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
import customtkinter
|
||||||
|
customtkinter.enable_macos_darkmode()
|
||||||
|
customtkinter.set_appearance_mode("System")
|
||||||
|
|
||||||
|
app = tkinter.Tk()
|
||||||
|
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")
|
||||||
|
print("Number:", dialog.get_input())
|
||||||
|
|
||||||
|
button = CTkButton(master=app, text="Open Dialog", command=button_click_event)
|
||||||
|
button.place(relx=0.5, rely=0.5, anchor=tkinter.CENTER)
|
||||||
|
|
||||||
|
app.mainloop()
|
||||||
|
customtkinter.disable_macos_darkmode()
|
@ -125,7 +125,7 @@ class CTkLabel(tkinter.Frame):
|
|||||||
self.draw()
|
self.draw()
|
||||||
|
|
||||||
def set_text(self, text):
|
def set_text(self, text):
|
||||||
self.text_label.configure(text=text)
|
self.text_label.configure(text=text, width=len(self.text))
|
||||||
|
|
||||||
def change_appearance_mode(self, mode_string):
|
def change_appearance_mode(self, mode_string):
|
||||||
if mode_string.lower() == "dark":
|
if mode_string.lower() == "dark":
|
||||||
|
BIN
documentation_images/customtkinter_mode_switch.gif
Normal file
BIN
documentation_images/customtkinter_mode_switch.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 MiB |
@ -9,9 +9,11 @@ root_tk = tkinter.Tk() # create the Tk window like you normally do
|
|||||||
root_tk.geometry("400x240")
|
root_tk.geometry("400x240")
|
||||||
root_tk.title("CustomTkinter Test")
|
root_tk.title("CustomTkinter Test")
|
||||||
|
|
||||||
|
|
||||||
def button_function():
|
def button_function():
|
||||||
print("button pressed")
|
print("button pressed")
|
||||||
|
|
||||||
|
|
||||||
# load images as PhotoImage
|
# load images as PhotoImage
|
||||||
settings_image = ImageTk.PhotoImage(Image.open("test_images/settings.png").resize((40, 40)))
|
settings_image = ImageTk.PhotoImage(Image.open("test_images/settings.png").resize((40, 40)))
|
||||||
bell_image = ImageTk.PhotoImage(Image.open("test_images/bell.png").resize((40, 40)))
|
bell_image = ImageTk.PhotoImage(Image.open("test_images/bell.png").resize((40, 40)))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user