Aka*_*ape -1 python tkinter python-3.x tkinter-layout
我想要一个像这样的布局,使用网格方法,其中顶部有 2 个小部件,可以正确填充而不会重叠,底部有 3 个小部件。
我尝试使用 columnspan 属性,但它是重叠的。
使用六列。顶部的两个项目各占 3 列,底部的项目各占两列。
import tkinter as tk
root = tk.Tk()
f1 = tk.Frame(root, width=100, height=100, background="red")
f2 = tk.Frame(root, width=100, height=100, background="orange")
f3 = tk.Frame(root, width=100, height=100, background="yellow")
f4 = tk.Frame(root, width=100, height=100, background="green")
f5 = tk.Frame(root, width=100, height=100, background="blue")
f1.grid(row=0, column=0, columnspan=3, sticky="nsew")
f2.grid(row=0, column=3, columnspan=3, sticky="nsew")
f3.grid(row=1, column=0, columnspan=2, sticky="nsew")
f4.grid(row=1, column=2, columnspan=2, sticky="nsew")
f5.grid(row=1, column=4, columnspan=2, sticky="nsew")
root.grid_columnconfigure((0,1,2,3,4,5), weight=1)
root.grid_rowconfigure((0,1), weight=1)
root.mainloop()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
75 次 |
| 最近记录: |