0
我有一个问题,我可以压缩此代码(我已告诉我可以)但没有得到任何帮助,这样做,并没有一个线索如何做到这一点。压缩我的类为我的tkinter窗口按钮
试过把它放到for循环中,但我想要一个3x3的按钮网格,中间的按钮是一个列表框,而不是按钮的死点。
我环顾四周,一小时后,我没有回答。
在这里,我尝试追加每个按钮到一个列表中,并将它们包装在一个for循环中,但它有可能在for循环中完成它们并且在完成后单独打包Listbox?
class MatchGame(Toplevel):
def __init__(self,master):
self.fr=Toplevel(master)
self.GameFrame=Frame(self.fr)
self.AllButtons=[]
self.AllButtons.append(Button(self.GameFrame,bg="red",height=5,width=15,text=""))
self.AllButtons.append(Button(self.GameFrame,bg="green",height=5,width=15,text=""))
self.AllButtons.append(Button(self.GameFrame,bg="dark blue",height=5,width=15,text=""))
self.AllButtons.append(Button(self.GameFrame,bg="turquoise",height=5,width=15,text=""))
self.AllButtons.append(Listbox(self.GameFrame,bg="grey",height=5,width=15))
self.AllButtons.append(Button(self.GameFrame,bg="yellow",height=5,width=15,text=""))
self.AllButtons.append(Button(self.GameFrame,bg="pink",height=5,width=15,text=""))
self.AllButtons.append(Button(self.GameFrame,bg="orange",height=5,width=15,text=""))
self.AllButtons.append(Button(self.GameFrame,bg="purple",height=5,width=15,text=""))
for x in range(0,len(self.AllButtons)):
AllButtons[x].grid(row=int(round(((x+1)/3)+0.5)),column=x%3)
self.GameFrame.grid(row=0,column=0)
Quit=Button(self.fr, text="Destroy This Game", bg="orange",command=self.fr.destroy)
Quit.grid(row=1,column=0)
它需要有单独的颜色,相同的大小和所有,但我不知道该怎么做。我对课程相当陌生,而且我无法解决我的生活如何使用紧凑的代码制作此窗口(每个对象不是9行,然后将它们全部打包)。
谢谢,我可以联系你,如果我遇到问题与建立的命令? –
欢迎您。虽然我不能答应立即回答。 –