简体   繁体   English

Tkinter label 没有被破坏

[英]Tkinter label isn't being destroyed

I wrote a little questionnaire and the questions won't be destroyed by clicking on the next or check button.我写了一个小问卷,点击下一步或检查按钮不会破坏问题。 Sometimes it works and sometimes not.有时它有效,有时无效。 It's really strange.这真的很奇怪。 The questions will be put on top of the old one.这些问题将放在旧问题之上。 It's like a pile of questions and that's really annoying.这就像一堆问题,这真的很烦人。

 def myLabeldestroy(self): myLabel01.destroy() def checkAnswer(self): ###Creation of random integers self.iniRand() ###Delete myLabel self.myLabeldestroy() self.mylabel(self.theories[self.qList][self.index][self.zero], 0, 1) ###Check whether answer is in used list or not if self.theories[self.qList] not in self.usedTheories: if self.gs[self.index][self.zero] not in self.used: ###Correct answer self.myEntry.get() == str(self.theories[self.qList][self.index][self.one]) self.used.append(self.gs[self.index][self.zero]) self.mylabel(self.answer[self.answerIndex], 2, 1) self.counter += self.one ###Point counter self.mylabel("Point counter " + str(self.counter), 4, 1) ###Wrong answer else: self.mylabel(self.reply[self.answerIndex], 2, 1) def nextAnswer(self): ###Creation of random integers self.iniRand() ###Delete myLabel self.myLabeldestroy() self.mylabel(self.theories[self.qList][self.index][self.zero], 0, 1) ###Check whether answer is in used list or not if self.theories[self.qList] not in self.usedTheories: if self.gs[self.index][self.zero] not in self.used: self.used.append(self.gs[self.index][self.zero]) self.counter -= self.one ###Point counter self.mylabel("Point counter " + str(self.counter), 4, 1)

I can advise you to use another method.If you are.pack() method, use pack_forget() or grid_forget() if you are using.grid().Learn more about it from here .我可以建议您使用另一种方法。如果您是 .pack() 方法,请使用 pack_forget() 或 grid_forget() 如果您正在使用.grid()。从这里了解更多信息。

I've found out my mistake.我发现了我的错误。 I had to create two destroy methods.我必须创建两个销毁方法。

 def myLabeldestroyStart(self): self.myLabelstart01.destroy() def myLabeldestroyQuestions(self): self.myLabelquestion01.destroy()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM