Skip to content

CTkToplevel

Tom Schimansky edited this page Oct 3, 2022 · 11 revisions

CTkToplevel works exactly like the Tkinter.Toplevel, and should be used to create more than one window.

Example Code:

import tkinter
import customtkinter


class ExampleApp(customtkinter.CTk):
    def __init__(self):
        super().__init__()

        self.geometry("500x400")

        self.button = customtkinter.CTkButton(self, text="Create Toplevel", command=self.create_toplevel)
        self.button.pack(side="top", padx=40, pady=40)

    def create_toplevel(self):
        window = customtkinter.CTkToplevel(self)
        window.geometry("400x200")

        # create label on CTkToplevel window
        label = customtkinter.CTkLabel(window, text="CTkToplevel window")
        label.pack(side="top", fill="both", expand=True, padx=40, pady=40)


app = ExampleApp()
app.mainloop()

The example code results in the following windows: Bildschirmfoto 2022-03-07 um 22 10 29

Arguments:

argument value
fg_color window background color, tuple: (light_color, dark_color) or single color

Methods:

  • .configure(attribute=value, ...)

    All attributes can be configured and updated.

    toplevel.configure(fg_color=new_fg_color)
  • .cget(attribute_name)

    Pass attribute name as string and get current value of attribute.

    fg_color = toplevel.cget("fg_color")
    ...
  • .title(string)

    Set title of window.

  • .geomtry(geometry_string)

    Set geometry and positions of the window like this: "<width>x<height>" or "<width>x<height>+<x_pos>+<y_pos>"

  • .minsize(width, height)

    Set minimal window size.

  • .maxsize(width, height)

    Set max window size.

  • .resizable(width, height)

    Define, if width and/or height should be resizablee with bool values.

  • .after(milliseconds, command)

    Execute command after milliseconds without blocking the main loop.

  • .withdraw()

    Hide window and icon. Restore it with .deiconify().

  • .iconify()

    Iconifies the window. Restore it with .deiconify().

  • .deiconify()

    Deiconify the window.

  • .state()

    Returns the window state: 'normal', 'iconic' or 'withdrawn'

⚠️ Attention ⚠️

The Github Wiki is outdated, the new documentation can be found at:

https://customtkinter.tomschimansky.com

Clone this wiki locally