我在循环中有一些代码输出2个按钮和一个标签,但之后它继续,但我希望它在用户点击按钮之前不做任何事情。如果你们中的任何一个人知道怎么做,那将会有所帮助。我没有任何命令,因为我不确定如何做到这一点。
"更"是用户想要另一张抽认卡,其中1为是,0为否。 x是你所使用的闪存卡。
while more == "1":
if x <= 1:
self.flashCardText = Label(self.flashcards, text = flashcard[x][y]).grid(row = 1, column = 2)
self.flipButton = Button(self.flashcards, text = "Flip", command = lambda: flip()).grid(row = 2, column = 1)
self.nextButton = Button(self.flashcards, text = "Next", command = lambda: x += 1).grid(row = 2, column = 3)
答案 0 :(得分:0)
目前你在while循环中创建了很多按钮。所以你可以这样做。你可以做的是创建某种对话框(例如下面的例子)。没有你的完整代码就不能说太多,但下面的例子应该是有用的:
from tkinter import *
top = Tk()
class Test(Frame):
def __init__(self, parent):
Frame.__init__(self, parent)
self.x = 0
flashCardText = Label(self, text = print('flashcard')).grid(row = 1, column = 2)
flipButton = Button(self, text = "Flip", command = lambda: print('flip')).grid(row = 2, column = 1)
nextButton = Button(self, text = "Next", command = self._test_output).grid(row = 2, column = 3)
self.grid()
def _test_output(self):
if self.x < 2:
print("increasing x")
self.x +=1
else:
print("x is 2")
self.master.destroy()
t = Test(top)
top.mainloop()
所以基本上,在这个例子中,测试窗口一直显示,直到self.x
到达2.&#39; self.x&#39;每次按下一步按钮都会增加。在这个例子中,其他按钮不会做太多。