-
Notifications
You must be signed in to change notification settings - Fork 1.1k
CTkToplevel
CTkToplevel works exactly like the Tkinter.Toplevel
, and should be used to create more than one window.
import customtkinter
class ToplevelWindow(customtkinter.CTkToplevel):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.geometry("400x300")
self.label = customtkinter.CTkLabel(self, text="ToplevelWindow")
self.label.pack(padx=20, pady=20)
class App(customtkinter.CTk):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.geometry("500x400")
self.button_1 = customtkinter.CTkButton(self, text="open toplevel", command=self.open_toplevel)
self.button_1.pack(side="top", padx=20, pady=20)
self.toplevel_window = None
def open_toplevel(self):
if self.toplevel_window is None or not self.toplevel_window.winfo_exists():
self.toplevel_window = ToplevelWindow(self) # create window if its None or destroyed
else:
self.toplevel_window.focus() # if window exists focus it
if __name__ == "__main__":
app = App()
app.mainloop()
The example code results in the following windows:
argument | value |
---|---|
fg_color | window background color, tuple: (light_color, dark_color) or single color |
-
All attributes can be configured and updated.
toplevel.configure(fg_color=new_fg_color)
-
Pass attribute name as string and get current value of attribute.
fg_color = toplevel.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: