这是我用来启动程序主要部分的函数的代码,但是我想要一些循环或其他的东西,它会创建十个问题,但是在进入下一个问题之前,要等待输入框的输入。 有什么想法吗?在
def StartGame():
root = Tk()
root.title("Maths Quiz - Trigonometry and Pythagoras' Theorem | Start The Game")
root.geometry("640x480")
root.configure(background = "gray92")
global AnswerEntry
TotScore = 0
Count = 0
AnswerReply = None
WorkingArea = Text(root, width = 70, height = 10, wrap = WORD).place(x = 38, y = 100)
n = GetRandomNumber()
Angle,Opposite,Adjacent,Hypotenuse = Triangle()
Question,RealAnswer = QuestionLibrary(Opposite,Adjacent,Hypotenuse,Angle,n)
AskQuestion = Label(root, text = Question, wraplength = 560).place(x = 48, y = 300)
PauseButton = ttk.Button(root, text = "Pause").place(x = 380, y = 10)
HelpButton = ttk.Button(root, text = "Help", command = helpbutton_click).place(x = 460, y = 10)
QuitButton = ttk.Button(root, text = "Quit", command = root.destroy).place(x = 540, y = 10)
AnswerEntry = Entry(root)
AnswerEntry.place(x = 252, y = 375)
SubmitButton = ttk.Button(root, text = "Submit", command = submit_answer).place(x = 276, y = 400)
TotScore,AnswerReply = IsAnswerCorrect(Answer,RealAnswer)
ScoreLabel = ttk.Label(root, text = TotScore).place(x = 38, y = 10)
AnswerReplyLabel = ttk.Label(root, text = AnswerReply).place(x = 295, y = 440)
root.mainloop()
我希望循环在AnswerReply = None
之后开始
我不知道Tk,但是没有
input text changed
的信号吗?应该是肯定的。只要检查一下这个信号是否出现,然后转到新的问题,因为这意味着有人在输入框中输入了一些东西。在你不需要循环。GUI中唯一真正重要的循环应该是
mainloop()
,它处理信号并执行回调。在示例:
我们只有一个标签,一个条目和一个按钮(我不在乎布局!,只要
pack()
)。在附加在按钮上的是一个命令(又名回调)。按下按钮后,将读取答案,并将新问题分配给标签。在
从“if名称=”main“块中的示例可以理解此类的用法。请注意:答案列表已填写到位,问题列表保持不变。在
相关问题 更多 >
编程相关推荐