Toplevel(顶级窗口),类似于弹出窗口,具有独立的窗口属性(如标题栏、边框等)
import tkinter as tk
# 建立窗口
window = tk.Tk()
window.title('hello thinter')
height= window.winfo_screenheight()
width= window.winfo_screenwidth()
window.geometry('400x200+%d+%d'%((width-400)/2,(height-200)/2))
def create():
top = tk.Toplevel()
top.title("tkinter")
msg = tk.Message(top, text="hello thinter!")
msg.pack()
tk.Button(window, text="创建顶级窗口", command=create).pack()
window.mainloop()
网友评论