我已经为分配给该课程的学校项目制作了测试代码,但是当我运行代码时,tkinter按钮会加载,但是当您按下数学部分上的按钮(唯一完成)时,代码会崩溃,任何帮助都会很好。
from tkinter import *
Window_Blank = Tk()
#Advanced Define
def MathA():
answer = input()
answer = int(answer)
print("If A=12*2 and B=15*3, What does AB-B= ")
if answer == 1035:
print("Correct")
else:
print("Incorrect")
print("The Answer was 1035")
def Math():
print(MathA())
return
def Science():
return
def Agriculture():
return
def Geographical():
return
#Basic Define
Frame1 = Frame(Window_Blank)
Frame2 = Frame(Window_Blank)
Frame3 = Frame(Window_Blank)
Frame4 = Frame(Window_Blank)
Button1 = Button(Frame1, text="Math Questions", fg="red", command=Math)
Button2 = Button(Frame2, text="Science Questions", fg="blue", command=Science)
Button3 = Button(Frame3, text="Agricultural Questions", fg="green", command=Agriculture)
Button4 = Button(Frame4, text="Geographical Questions", fg="purple", command=Geographical)
#Framework for the menu
Frame1.grid(row=0, column=0)
Frame2.grid(row=0, column=1)
Frame3.grid(row=0, column=2)
Frame4.grid(row=0, column=3)
Button1.grid(row=1)
Button2.grid(row=2)
Button3.grid(row=3)
Button4.grid(row=4)
Window_Blank.mainloop()
答案 0 :(得分:0)
改变这个:
def MathA():
print("If A=12*2 and B=15*3, What does AB-B= ")
answer = input()
answer = int(answer)
if answer == 1035:
print("Correct")
else:
print("Incorrect")
print("The Answer was 1035")
和
def Math():
MathA()
return