【发布时间】:2016-02-17 11:15:56
【问题描述】:
我无法运行程序。但是没有错误表明代码错误我想制作一个测验程序,如何将此代码与我的其他代码结合使用我们需要使用 TopLevel 吗? .这是我的代码:
import Tkinter
MathsEasyLevel1 = Tkinter.Tk()
MathsEasyLevel1.geometry("320x260")
MathsEasyLevel1.title("Mathematics Easy")
total = 0
getanswer = Tkinter.IntVar()
getanswer2 = Tkinter.StringVar()
def userinput():
Answer1 = getanswer.get()
if Answer1 == 8 :
total = total + 1
MathsEasyLevel1.withdraw()
MathsEasyLevel2.deiconify()
else :
total = total
MathsEasyLevel1.withdraw()
MathsEasyLevel2.deiconify()
return
def userinput2():
Answer2 = getanswer2.get()
if Answer2 == B :
total = total + 1
MathsEasyLevel2.withdraw()
ResultBox.deiconify()
else :
total = total
MathsEasyLevel2.withdraw()
ResultBox.deiconify()
return
LabelName1 = Tkinter.Label (MathsEasyLevel1, text="Question 1", font=("Impact",20))
LabelName1.grid(row=0,column=2,sticky="new")
LabelName2 = Tkinter.Label (MathsEasyLevel1, text="State the number of edges in a cube")
LabelName2.grid(row=1,column=0)
LabelName2.pack()
TxtBoxName = Tkinter.Entry (MathsEasyLevel1, textvariable= getanswer)
TxtBoxName.grid(row=2,column=0)
TxtBoxName.pack()
MathsEasyLevel2 = Tkinter.Tk()
MathsEasyLevel2.geometry("320x260")
MathsEasyLevel2.title("Mathematics Easy")
BtnName = Tkinter.Button (MathsEasyLevel1, text="Next", command=userinput).pack()
LabelName3 = Tkinter.Label (MathsEasyLevel2, text="Question 2", font=("Impact",20))
LabelName3.grid(row=0,column=2,sticky="new")
LabelName3 = Tkinter.Label (MathsEasyLevel2, text="What is the place value of the digit 4 in 76421?")
LabelName3.grid(row=1,column=0)
LabelName3.pack()
LabelName4 = Tkinter.Label (MathsEasyLevel2, text="A.Thousands B.Hundreds C.Ones D.Tens")
LabelName4.grid(row=2,column=0)
LabelName4.pack()
TxtBoxName2 = Tkinter.Entry (MathsEasyLevel2, textvariable= getanswer2)
TxtBoxName2.grid(row=3,column=0)
TxtBoxName2.pack()
BtnName2 = Tkinter.Button (MathsEasyLevel2, text="Next", command=userinput2).pack()
MathsEasyLevel2.withdraw()
ResultBox = Tkinter.Tk()
ResultBox.geometry("320x260")
ResultBox.title("Results")
LabelName5 = Tkinter.Label (ResultBox, text="Total correct answers :"+ `total` , font=("Impact",20))
LabelName5.grid(row=1,column=0,sticky="new")
LabelName5 = Tkinter.Label (ResultBox, text="Marks : "+`(total/2*100)`, font=("Impact",20))
LabelName5.grid(row=2,column=0)
ResultBox.withdraw()
def userinput3():
ResultBox.withdraw()
MenuBox.deiconify()
return
MathsEasyLevel1.mainloop()
【问题讨论】:
-
@WoLy 这是我的其他代码与关卡代码相结合,但我想先测试它,但它没有运行
-
@adrianus 你能检查我的问题吗?我的 mark() 函数在结果框中无法正常工作
标签: python-2.7 user-interface python-3.x coding-style