我正在制作一张 table , table 的网格将被按钮填满,是否可以在网格空间中放置多个按钮?
最佳答案
是的你可以。在单元格内放一个框架,然后你可以在框架内放任何你想要的东西。在框架内,您可以使用 pack
、 place
或 grid
,因为它独立于其余小部件。
例如:
import Tkinter as tk
root = tk.Tk()
l1 = tk.Label(root, text="hello")
l2 = tk.Label(root, text="world")
f1 = tk.Frame(root)
b1 = tk.Button(f1, text="One button")
b2 = tk.Button(f1, text="Another button")
l1.grid(row=0, column=0)
l2.grid(row=0, column=1)
f1.grid(row=1, column=1, sticky="nsew")
b1.pack(side="top")
b2.pack(side="top")
root.mainloop()
关于python-3.x - 您可以在 tkinter 的一个网格单元中放置多个按钮吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38153754/