【发布时间】:2016-02-18 07:36:13
【问题描述】:
我猜我的结构代码是错误的。因为 tkmassagebox 信息总是显示 C。据说当总数 = 3 时,tkmassagebox 显示 A。虽然总数得到 3 正确,但结果仍然保持不变 C。有人可以修复我的问题。下面是我的代码,你们可以自己试试。
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()
【问题讨论】:
-
@WoLy 请帮我最后一次
-
您不应创建多个根窗口。 Tkinter 被设计为始终只有一个
Tk实例。如果您需要额外的窗口,您应该创建Toplevel的实例。
标签: python python-2.7 tkinter coding-style