我在用Tkinter做复习测验。程序将自动从数组中获取问题,然后使用标签输出问题。当按下submit按钮时,程序将检查答案,然后应该将标签更新到数组中的下一个问题,但是没有,没有错误消息。分数更新了,但是标签没有更新。你知道吗
def entryQuestion():
entryOpen = open('./files/entry.csv','r')
entryFile = csv.reader(entryOpen, delimiter = ',')
global entryQuestionArray
entryQuestionArray = []
for topic, question, answer in entryFile:
for i in range(0,1):
entryQuestionArray.append(question)
entryQuestionArray = random.sample(entryQuestionArray, len(entryQuestionArray))
arrayLength = len(entryQuestionArray)
for x in entryQuestionArray:
global qOut
qOut = x
global entryQuestion
entryQuestion = Label(entryQ, text = x)
entryQuestion.grid(row = 1, column = 0, columnspan = 3)
global answerEntry
answerEntry = StringVar()
global answerEntryBox
answerEntryBox = Entry(entryQ, textvariable = answerEntry)
answerEntryBox.grid(row = 2, column = 0, columnspan = 3)
submitEntryAnswer = Button(entryQ, text = 'Submit Answer', command = entryQuestionCheck)
submitEntryAnswer.grid(row = 3, column = 2)
def entryQuestionCheck():
entryOpen = open('./files/entry.csv','r')
entryFile = csv.reader(entryOpen, delimiter = ',')
tempScore = score
for topic, question, answer in entryFile:
if qOut == question:
if answerEntry.get() == answer:
tempScore = tempScore + 1
else:
tempScore = tempScore + 0
return
有人能帮忙吗?你知道吗
每个小部件只需要一个调用,在顶部或主类中,您只需要调用他一次:
在函数中,如果你需要改变你的值,比如文本,你只需要把自我值传递给函数,然后改变他,像这样:
或:
在主类或作用域中,需要使用值调用函数,如果在作用域中(不在类中),则需要在值中传递小部件:
或:
相关问题 更多 >
编程相关推荐