基本上,我有这个代码:
from tkinter import *
from tkinter import messagebox
import random
import string
from tkinter import filedialog
ktwoWin = Tk() #window
qLabel = StringVar()
userAnswer = StringVar()
ktwoWin.withdraw() #hide the ktwoWin window
pass
num1= random.randint(1, 12) #random numbers
num2= random.randint(1, 12)
Answer= num1 * num2
def ktwoOpen():
ktwoWin.deiconify() #show the ktwoWin window
ktwoWin.title("Kindergarten to Grade Two")
ktwoWin.geometry("400x300")
ktwoWin.grid()
askbutton= Button(ktwoWin, text="ask me a question!", command = askquestion, height=3, width=16, bg="blue")
askbutton.grid(column= 0, row= 0)
submitbtn= Button(ktwoWin, text="Submit Answer", command=checkanswer, height=3, width=12, bg= "red")
submitbtn.grid(column=1, row=0)
q=Label(ktwoWin,textvariable=qLabel)
q.grid(column=1, row=1)
q.config(text="text to go here")
qLabel.set("some text")
answerentry= Entry(ktwoWin, textvariable=userAnswer)
answerentry.grid(column=3, row=3)
pass
def askquestion():
qLabel.set("what is" +str(num1) + "x" + str(num2) + "?")
def checkanswer():
useranswer=userAnswer.get()
if int(useranswer) != Answer:
messagebox.showwarning(message="the answer is " + str(Answer))
else:
messagebox.showinfo(message="correct!")
ktwoWin.mainloop
哪个,当我运行程序时,我拥有的随机数只会随机化一次,如果这有意义的话?我的问题,最终,有没有办法让我循环代码的随机数部分?任何帮助表示赞赏,谢谢:)