Tinker Toplevel Tutorial
Basic concept of Toplevel window
The function of this control is similar to Frame, but the container produced by this control is a separate window with its own title bar and border. The syntax of its constructor is as follows.
Toplevel(Options, ...)
The following are other commonly used options parameters within the LabelFrame( ) method.
(1) bg or background
: background color.
(2) borderwidth or bd
: label border width, default is 2.
(3) cursor
: the shape of the cursor when the mouse cursor is on the Toplevel window.
(4) fg
: the foreground color of the text.
(5) font
: font shape.
(6) height
: height of the window.
(7) width
: width of the window.
Tinker Toplevel Tutorial Example#1
建立一个Toplevel窗口,为了区分在Toplevel窗口中增加字符串“I am a toplevel.”。
from tkinter import *
root = Tk()
root.title("apidemos.com")
# root.geometry("400x320")
tl = Toplevel()
Label(tl,text="I am a Toplevel!").pack()
root.mainloop()
Output:
The result after moving the main window moderately:
After the Toplevel window is created, if you close the Toplevel window, the original main window can still be used, but if you close the main window, the Toplevel window will be closed automatically. In Tkinter Window properties, we have described the methods of setting window properties when creating the main window. Some of these methods can be used by Toplevel windows.
Tinker Toplevel Tutorial Example#2
Set the title and size of the Toplevel window.
from tkinter import *
root = Tk()
root.title("apidemos.com")
tl = Toplevel()
tl.title("Toplevel")
tl.geometry("300x180")
Label(tl,text="I am a Toplevel!").pack()
root.mainloop()
Output: