Toplevel
Toplevel is a container widget that is very similar to "another" window within your application
import tkinter base = tkinter.Tk() base.title("base") window1 = tkinter.Toplevel() window1.title("window1") base.mainloop()
To practice a bit more with Toplevel:
import tkinter def changewindow(): window1.geometry("100x100") base = tkinter.Tk() base.title("base") b = tkinter.Button(base, text="Make it smaller", command=changewindow) b.pack() window1 = tkinter.Toplevel() window1.title("window1") base.mainloop()
If you want to pass arguments to a command function you can do it using lambda:
import tkinter def changewindow(t): window1 = tkinter.Toplevel() window1.title(t) base = tkinter.Tk() base.title("base") b = tkinter.Button(base, text="Make a new window", command=lambda:changewindow(title)) title="123" b.pack() base.mainloop()
Common Toplevel options:
Option | Description |
bg | The background color of the window. |
bd | Border width in pixels; default is 0. |
cursor | The cursor that appears when the mouse is in this window. |
class_ | Normally, text selected within a text widget is exported to be the selection in the window manager. Set exportselection=0 if you don't want that behavior. |
font | The default font for text inserted into the widget. |
fg | The color used for text (and bitmaps) within the widget. You can change the color for tagged regions; this option is just the default. |
height | Window height. |
relief | Normally, a top-level window will have no 3-d borders around it. To get a shaded border, set the bd option larger that its default value of zero, and set the relief option to one of the constants. |
width | The desired width of the window. |