我将tkinter用作一个带有函数的类,但是当我运行一个函数导致另一个函数时,它又会以再次运行第一个函数结束,但是原来的函数不起作用。请帮忙
def idle(self):
self.next.destroy()
self.info.destroy()
self.prompt.configure(text=city_line + ", What do you want to do?")
self.backpack = tk.Button(self, text="Backpack", command=self.backpack)
self.shop = tk.Button(self, text="Shop")
self.wander = tk.Button(self, text="Wander", command=self.wander)
self.travel = tk.Button(self, text="Travel", command=self.travel)
self.backpack.pack(side="right", padx=5, pady=5)
self.shop.pack(side="right", padx=5, pady=5)
self.wander.pack(side="right", padx=5, pady=5)
self.travel.pack(side="right", padx=5, pady=5)
def backpack(self):
self.backpack.destroy()
self.shop.destroy()
self.wander.destroy()
self.travel.destroy()
self.output.destroy()
self.info = tk.Message(self, width=150, text=backpacke + ". Gold: " + str(gold))
self.output = tk.Label(self, text="")
self.next = tk.Button(self, text="Next", command=self.idle)
self.info.pack(side="top", fill="x", pady=8)
self.output.pack(side="top", fill="x", expand=True)
self.next.pack(side="right", padx=5, pady=5)
创建类时,有一个名为
backpack
的方法。在类中,self.backpack
引用这个方法。当调用此方法时,它执行self.backpack = tk.Button(...)
,这将有效地销毁该方法并用小部件替换它。下次尝试调用self.backpack
时,您调用的是小部件而不是方法。你知道吗您需要为保存小部件的方法或变量选择不同的名称。你知道吗
相关问题 更多 >
编程相关推荐