简体   繁体   English

简单的数学测验

[英]Simple math quiz

My simple math quiz has error it shows that B variable in not defined. 我的简单数学测验有错误,表明未定义B变量。 I try to defined it as stringvar but still has error.Where should i define the variable?And is my total is the right way to make it continue to calculate fo last interface which is in result box.Can someone shows example to solve it. 我尝试将其定义为stringvar但仍然有错误。我应该在哪里定义变量?我的总计是使它继续计算结果框中最后一个接口的正确方法。有人可以显示示例来解决它。

import Tkinter 
import tkMessageBox

#easybox1
EasyBox1 = Tkinter.Tk()
EasyBox1.geometry("250x200")
EasyBox1.title("Quesion 1")

Tkinter.Label (EasyBox1, text="answer:").pack()

answr1 = Tkinter.Entry (EasyBox1)
answr1.pack()

LabelName2 = Tkinter.Label (EasyBox1, text="State the number of edges in a cube")
LabelName2.grid(row=1,column=0)
LabelName2.pack()

def next1():
    total = 0
    if not answr1.get():
       tkMessageBox.showerror('no answer')
    elif answr1.get() == 8 :
       total = total + 1
       EasyBox1.withdraw()
       EasyBox2.deiconify()
    elif answr1.get() != 8:
       total = total
       EasyBox1.withdraw()
       EasyBox2.deiconify()
    return

EasyBox2 = Tkinter.Tk()
EasyBox2.geometry("250x200")
EasyBox2.title("Quesion 2")

Tkinter.Label (EasyBox2, text="answer:").pack()

answr2 = Tkinter.Entry (EasyBox2)
answr2.pack()

LabelName2 = Tkinter.Label (EasyBox2, text="What is the place value of the digit 4 in 76421?")
LabelName2.grid(row=1,column=0)
LabelName2.pack()

LabelName2 = Tkinter.Label (EasyBox2, text="A.Thousands B.Hundreds C.Ones D.Tens")
LabelName2.grid(row=1,column=0)
LabelName2.pack()

def mark():
    total = 0
    if not answr2.get():
        tkMessageBox.showerror('no answer')
    elif answr2.get() == B or b :
        total = total + 1
        EasyBox1.withdraw()
        ResultBox.deiconify()
    elif answr2.get() != B :
        total = total
        EasyBox1.withdraw()
        ResultBox.deiconify()
    return


EasyBox2.withdraw()

total = 0


ResultBox = Tkinter.Tk()
ResultBox.geometry("320x260")
ResultBox.title("Results")

LabelName5 = Tkinter.Label (ResultBox, text="Marks : "+`total`, font=("Impact",20))
LabelName5.grid(row=2,column=0)
ResultBox.withdraw()

Tkinter.Button (EasyBox1, text="Next", command=next1).pack()
Tkinter.Button (EasyBox2, text="result", command=mark).pack()

EasyBox1.mainloop()

如果您想将答案与字符串“ B”或“ b”进行比较,只需将其引号

Just put quotation marks around "b" and "B" : 只需在"b""B"两边加上引号:

def mark():
    total = 0
    if not answr2.get():
        tkMessageBox.showerror('no answer')
    elif answr2.get() in ["B", "b"]:
        total = total + 1
        EasyBox1.withdraw()
        ResultBox.deiconify()
    else:
        total = total
        EasyBox1.withdraw()
        ResultBox.deiconify()

Also, the comparison with or "b" won't work right now, you could change it to 另外,与or "b"的比较现在将无法进行,您可以将其更改为

if answr2.get() in ["B", "b"]:

or 要么

if answr2.get().upper() == "B":

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM