Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 简单数学测验_Python_Python 2.7_User Interface_Callback_Counter - Fatal编程技术网

Python 简单数学测验

Python 简单数学测验,python,python-2.7,user-interface,callback,counter,Python,Python 2.7,User Interface,Callback,Counter,我的简单数学测验有一个错误,它表明B变量没有定义。我试图将其定义为stringvar,但仍然有错误。我应该在哪里定义变量?我的合计是使其继续计算结果框中最后一个接口的正确方法。是否有人可以给出示例来解决此问题 import Tkinter import tkMessageBox #easybox1 EasyBox1 = Tkinter.Tk() EasyBox1.geometry("250x200") EasyBox1.title("Quesion 1") Tkinter.Label (E

我的简单数学测验有一个错误,它表明B变量没有定义。我试图将其定义为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”进行比较,只需将其引用即可

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

只需在
“B”
“B”
周围加上引号即可:

此外,与
或“b”
的比较现在也不起作用,您可以将其更改为

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


只需在
“b”
“b”
周围加上引号:

此外,与
或“b”
的比较现在也不起作用,您可以将其更改为

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


@WoLy这是我为问题级界面编辑的,你能更正吗?@WoLy这是我为问题级界面编辑的,你能更正吗?thnx但是如果两个问题都正确,如何打印出分数?即使我的答案是正确的,也表明Marko代码有几个问题,包括全局
total
变量,并且当
total
始终为零时,在启动时生成ResultBox。看看这个要点:还有别的办法吗?实际上,在结果框中,我想转换成百分比分数。如果变量定义为全局变量,则无法将总变量转换为百分比。我很感激你所做的代码。thnx但是如果两个问题都正确,如何打印出分数?即使我的答案是正确的,也表明Marko代码有几个问题,包括全局
total
变量,以及在启动时生成ResultBox,此时
total
始终为零。看看这个要点:还有别的办法吗?实际上,在结果框中,我想转换成百分比分数。如果变量定义为全局变量,则无法将总变量转换为百分比。我很感激你所做的代码。
if answr2.get().upper() == "B":