0
我正在嘗試爲等級創建計算器,爲用戶輸入類別的權重以及它們在總分上的標記。然後我想輸出他們的成績(以%計)。但是,在試圖獲取框中的文本時,我收到一個錯誤,說我的條目沒有定義。嘗試對條目中提供的整數進行數學運算時出錯
錯誤消息:https://gyazo.com/1d9c5a086a7d369b69500d5399d4b08e
看一看:
b1v=float(bl.get())
它需要:
from Tkinter import *
import random
player = 1
count=0
menu=Tk()
menu.wm_title("Percentage Calculator")
def Calculate():
global a1
global a2
global b1
global b2
global c1
global c2
global d1
global d2
tval=int(tvalue.get())
aval=int(avalue.get())
cval=int(cvalue.get())
kval=int(kvalue.get())
a1v=float(a1.get())
a2v=float(a2.get())
total_t=(((a1v/a2v)*100)/tval)
b1v=float(bl.get())
b2v=float(b2.get())
total_a=(((b1v/b2v)*100)/aval)
c1v=float(cl.get())
c2v=float(c2.get())
total_c=(((c1v/c2v)*100)/cval)
d1v=float(dl.get())
d2v=float(d2.get())
total_k=(((d1v/d2v)*100)/kval)
menutext=Label(text="Enter Percentages:",font="Arial 15")
menutext.grid(row=0,column=0,columnspan=4,sticky="NS,WE")
t=Label(text="T",font="Arial 15")
t.grid(row=1,column=0,sticky="NS,WE")
a=Label(text="A",font="Arial 15")
a.grid(row=1,column=1,sticky="NS,WE")
c=Label(text="C",font="Arial 15")
c.grid(row=1,column=2,sticky="NS,WE")
k=Label(text="K",font="Arial 15")
k.grid(row=1,column=3,sticky="NS,WE")
tvalue=Entry(font="Arial 15")
tvalue.grid(row=2,column=0,sticky="NS,WE")
avalue=Entry(font="Arial 15")
avalue.grid(row=2,column=1,sticky="NS,WE")
cvalue=Entry(font="Arial 15")
cvalue.grid(row=2,column=2,sticky="NS,WE")
kvalue=Entry(font="Arial 15")
kvalue.grid(row=2,column=3,sticky="NS,WE")
calcbutton=Button(text=" Calculate ",font="Arial 15",command=Calculate)
calcbutton.grid(row=10,column=0,columnspan=4,sticky="NS,WE")
menutext2=Label(text="Enter Marks:",font="Arial 15")
menutext2.grid(row=3,column=0,columnspan=4,sticky="NS,WE")
a1=Entry(font="Arial 15")
a1.grid(row=4,column=0,sticky="NS,WE")
a2=Entry(font="Arial 15")
a2.grid(row=4,column=1,sticky="NS,WE")
b1=Entry(font="Arial 15")
b1.grid(row=4,column=2,sticky="NS,WE")
b2=Entry(font="Arial 15")
b2.grid(row=4,column=3,sticky="NS,WE")
c1=Entry(font="Arial 15")
c1.grid(row=5,column=0,sticky="NS,WE")
c2=Entry(font="Arial 15")
c2.grid(row=5,column=1,sticky="NS,WE")
d1=Entry(font="Arial 15")
d1.grid(row=5,column=2,sticky="NS,WE")
d2=Entry(font="Arial 15")
d2.grid(row=5,column=3,sticky="NS,WE")
def AnswerDisplay():
##this is not complete yet, ignore
answerlabel=Label(text="Results Are...",font="Arial 15")
answerlabel.grid(row=7,column=0,columnspan=4,sticky="NS,WE")
a1ans=Label(text="null",font="Arial 20")
a1ans.grid(row=8,column=0,sticky="NS,WE")
b1ans=Label(text="null",font="Arial 20")
b1ans.grid(row=8,column=1,sticky="NS,WE")
c1ans=Label(text="null",font="Arial 20")
c1ans.grid(row=8,column=2,sticky="NS,WE")
d1ans=Label(text="null",font="Arial 20")
d1ans.grid(row=8,column=3,sticky="NS,WE")
menu.mainloop()
請不要鏈接到其他網站上的錯誤消息的圖片。花時間將消息文本複製並粘貼到問題中。 –