如何回调全局变量

时间:2016-02-18 04:40:27

标签: python user-interface tkinter global-variables

我正在为我的电子学习问题制作界面,这很容易出现问题。这是我在此社区中之前提问的问题。虽然答案是正确的,但是tkmassagebox显示的相同吗?如何回调全部结果可能会有所不同吗?它总是显示信息C.如果所有正确的话应该得到A.这是我的代码希望你们可以运行它来了解问题

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()

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

#easybox2
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 next2():
    global total
    if not answr2.get():
        tkMessageBox.showerror('no answer')
    elif answr2.get() in ["B", "b"]:
        total=total+1
        EasyBox2.withdraw()
        EasyBox3.deiconify()
    else:
        total=total
        EasyBox2.withdraw()
        EasyBox3.deiconify()


EasyBox2.withdraw()


#easybox3
EasyBox3 = Tkinter.Tk()
EasyBox3.geometry("250x200")
EasyBox3.title("Quesion 2")

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

answr3 = Tkinter.Entry (EasyBox3)
answr3.pack()

LabelName2 = Tkinter.Label (EasyBox3, text="1234+143x23=?")
LabelName2.grid(row=1,column=0)
LabelName2.pack()

def next3():
    global total
    if not answr3.get():
        tkMessageBox.showerror('no answer')
    elif answr3.get == 4523:
        total=total+1
        EasyBox3.withdraw()
        ResultBox.deiconify()
    else:
        total=total
        EasyBox3.withdraw()
        ResultBox.deiconify()

EasyBox3.withdraw()



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

LabelName5 = Tkinter.Label(ResultBox, text = "Mark"+`total`+'\n')
LabelName5.pack

def mark():
    global total_mark
    total_mark = total
    if total_mark == 3:
        tkMessageBox.showinfo('A')
    elif total_mark == 2:
        tkMessageBox.showinfo('B')
    else:
        tkMessageBox.showinfo('C')
ResultBox.withdraw()

Tkinter.Button (EasyBox1, text="Next", command=next1).pack()
Tkinter.Button (EasyBox2, text="Next", command=next2).pack()
Tkinter.Button (EasyBox3, text="Next", command=next3).pack()
Tkinter.Button (ResultBox, text="Result", command=mark).pack()


EasyBox1.mainloop()

0 个答案:

没有答案