-
Notifications
You must be signed in to change notification settings - Fork 1.1k
CTk (tkinter.Tk)
The CTk class creates the basis of any CustomTkinter program, it creates the main app window. During the runtime of a program there should only be one instance of these class with a single call of the .mainloop()
method, which starts the app. Additional windows are created using the CTkToplevel class.
Structure of a CustomTkinter program without any class (not recommended):
app = customtkinter.CTk()
app.geometry("600x500")
app.title("CTk example")
... program ...
app.mainloop()
Structure of a simple program with classes (recommended):
import customtkinter
class App(customtkinter.CTk):
def __init__(self):
super().__init__()
self.geometry("600x500")
self.title("CTk example")
# add widgets to app
self.button = customtkinter.CTkButton(self, command=self.button_click)
self.button.grid(row=0, column=0, padx=20, pady=10)
# add methods to app
def button_click(self):
print("button click")
app = App()
app.mainloop()
argument | value |
---|---|
fg_color | window background color, tuple: (light_color, dark_color) or single color |
-
All attributes can be configured and updated.
app.configure(fg_color=new_fg_color)
-
Pass attribute name as string and get current value of attribute.
fg_color = app.cget("fg_color") ...
-
Set title of window.
-
Set geometry and positions of the window like this:
"<width>x<height>"
or"<width>x<height>+<x_pos>+<y_pos>"
-
Set minimal window size.
-
Set max window size.
-
Define, if width and/or height should be resizablee with bool values.
-
Execute command after milliseconds without blocking the main loop.
-
Hide window and icon. Restore it with .deiconify().
-
Iconifies the window. Restore it with .deiconify().
-
Deiconify the window.
-
Returns the window state:
'normal', 'iconic' or 'withdrawn'
CustomTkinter by Tom Schimansky 2022
The Github Wiki is outdated, the new documentation can be found at: