【发布时间】:2015-02-07 02:37:48
【问题描述】:
我正在为 TKinter 中的游戏创建一个网格,我希望在蓝色瓷砖网格下方或旁边有按钮。我已经试过了:
from tkinter import *
class BattleScreen(Frame):
def __init__(self, root):
Frame.__init__(self, root)
self.grid()
for row in range(20):
for col in range(20):
butt1 = Button(self, bg='blue', width=1)
butt1.grid(row=row, column=col)
#self.but_frame = Frame(self)
#self.but_frame.pack(fill=X)
button1 = Button(self, text='Quit', width=6, command=lambda root=root:root.destroy())
button1.grid(row=21)
root = Tk()
sheet = BattleScreen(root)
root.mainloop()
当它运行时,它会在蓝色图块下方创建按钮,但由于它们都在同一个网格上并且按钮更宽,它会弄乱按钮上方的所有内容。
您看到的被注释掉的两行代码是我尝试创建另一个与网格框架分开的框架来放置按钮,但我想您不能这样做。我错了吗?
如何在网格中的蓝色图块下方或旁边获取按钮,而不会弄乱蓝色图块的对齐方式?
【问题讨论】:
-
是战列舰吗
标签: python button python-3.x tkinter grid