1
我的代碼創建一個Tk
窗口,其中包含3個輸入框和3個按鈕。當點擊一個按鈕時,相鄰的輸入框和按鈕本身應該消失。我想用摧毀,因爲我不再使用它。問題在於它在任何按鈕/入口組件上都是第一次工作,但是當我在其中一個銷燬後單擊其他任何按鈕時,其他按鈕都不會銷燬。destroy()不會破壞重複
class BlackjackTable:
def __init__(self,numPlayers):
self.numPlayers=numPlayers
self.tableWindow=Tk()
self.bettedE=False
self.bettedS=False
self.bettedW=False
self.betCount=0
self.suitWindow()
def suitWindow(self):
self.tableWindow.title("Blackjack Table")
self.tableWindow.config(bg="dark green")
if int(self.betCount)!=int(self.numPlayers) and (not self.bettedE):
self.EHandEntry=Entry(self.tableWindow,fg="white",bg="dark green",width=10)
self.EHandEntry.grid(row=5,column=9)
self.EHandSubmit=Button(self.tableWindow,text="Bet",fg="white",padx=15,pady=5,command=self.betE,bg="dark green",activebackground="dark green",activeforeground="white")
self.EHandSubmit.grid(row=5,column=10)
if self.numPlayers>=2:
if (self.betCount!=self.numPlayers) and (not self.bettedS):
self.SHandEntry=Entry(self.tableWindow,fg="white",bg="dark green",width=10)
self.SHandEntry.grid(row=8,column=6)
self.SHandSubmit=Button(self.tableWindow,text="Bet",fg="white",padx=15,pady=5,command=self.betST,bg="dark green",activebackground="dark green",activeforeground="white")
self.SHandSubmit.grid(row=8,column=7)
if self.numPlayers==3:
if (self.betCount!=self.numPlayers) and (not self.bettedW):
self.WHandEntry=Entry(self.tableWindow,fg="white",bg="dark green",width=10)
self.WHandEntry.grid(row=5,column=3)
self.WHandSubmit=Button(self.tableWindow,text="Bet",fg="white",padx=15,pady=5,command=self.betW,bg="dark green",activebackground="dark green",activeforeground="white")
self.WHandSubmit.grid(row=5,column=4)
def betE(self):
print("betE")
self.bettedE=True
self.EHandSubmit.destroy()
self.EHandEntry.destroy()
self.suitWindow()
self.betCount+=1
def betST(self):
print("betST")
self.bettedS=True
self.SHandSubmit.destroy()
self.SHandEntry.destroy()
self.suitWindow()
self.betCount+=1
def betW(self):
print("betW")
self.bettedW=True
self.WHandSubmit.destroy()
self.WHandEntry.destroy()
self.suitWindow()
self.betCount+=1
gui=BlackjackTable(3)
mainloop()