1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
def create_custom_window():
win = tk.Toplevel(root)
win.geometry("300x200")
# 标题
title = tk.Label(win, text="自定义窗口", font=("Arial", 14, "bold"))
title.place(relx=0.5, rely=0.1, anchor="center")
# 内容
content = tk.Label(win, text="这是使用place布局的自定义窗口", wraplength=250)
content.place(relx=0.5, rely=0.4, anchor="center")
# 关闭按钮
close_btn = tk.Button(win, text="关闭", command=win.destroy)
close_btn.place(relx=0.5, rely=0.8, anchor="center", width=80, height=30)
# 装饰元素
decor1 = tk.Label(win, bg="gold", width=5, height=1)
decor1.place(x=0, y=0)
decor2 = tk.Label(win, bg="gold", width=5, height=1)
decor2.place(relx=1.0, rely=1.0, anchor="se")
# 主窗口按钮
main_btn = tk.Button(root, text="创建窗口", command=create_custom_window)
main_btn.place(relx=0.5, rely=0.7, anchor="center")
root.mainloop()
|