2016-02-17 39 views
-1

我無法運行程序。但沒有錯誤顯示代碼錯誤我想做一個測驗程序,以及如何將此代碼與我的其他代碼結合起來我們需要使用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() 
+0

@WoLy這是我的其他代碼與級代碼合併,但我想對此進行測試,但它並沒有運行 – student

+0

@adrianus你可以檢查我的問題,我的我的標記()函數沒有resultbox正常工作 – student

回答

0

請提供更多關於如何嘗試運行此操作的信息,以及您所獲得的「輸出」是什麼。你有錯誤嗎?它運行正常嗎?另外,我建議使用主類而不是在文件中間運行代碼。

@edit而接下來的時間請儘量使標題更具代表性(語言等)

+0

我的輸出是結果框deiconify顯示總標記。在resultbox deiconify之前將按鈕在matheasylev el2顯示計算標記 – student

+0

我已經找到解決方案但我的結果標記無法正常工作 – student

0

我已經找到了解決辦法,但對於resultbox犯規work.It犯規計算total.These的標誌是我的新代碼:

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 
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() in ["B", "b"]: 
     total = total + 1 
     EasyBox1.withdraw() 
     ResultBox.deiconify() 
    else: 
     total = total 
     EasyBox1.withdraw() 
     ResultBox.deiconify() 


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() 
相關問題