저는 파이썬에 매우 익숙하며 특정 시험을 치르기 위해 최종 시험에 필요한 점수를 계산하는 tkinter를 사용하여 GUI를 만들려고합니다.NameError : name 's2gradefloat'이 정의되지 않았습니다.
from tkinter import *
root = Tk()
root.geometry("600x550+300+50")
root.title("")
backgroundcolor = '#%02x%02x%02x' %(0,0,0)
root.config(background= backgroundcolor)
#------------------Calculation----------------------#
def crscore():
s2grade = float(s2gradef.get())
dgrade = float(dgradef.get())
rscore = (100*dgrade - (100 - 50)* s2grade)/50
rscorelabel=Label(root,text="Required Test Score: %s" %rscore).place(x=250,y=370)
return
#------------------Labels----------------------#
Label1=Label(root,
text='Final Exam Calclulator',
fg='white',
bg='black',
font= "a 17 bold").place(x=170,y=20)
Label3=Label(root,
text='Enter Current Semester 2 Grade',
fg='white',
bg='black',
font= "a 12 bold").place(x=100,y=100)
Label4=Label(root,
text='Enter Desired Final Grade',
fg='white',
bg='black',
font= "a 12 bold").place(x=100,y=165)
#------------------EntryBoxes----------------------#
s2grade = StringVar()
dgrade = StringVar()
s2grade = Entry(root,textvariable=s2grade).place(x=395,y=100)
dgrade = Entry(root,textvariable=dgrade).place(x=360,y=165)
#------------------Button----------------------#
button1=Button(root,text='Calculate Required Score',command=crscore).place(x=250,y=240)
root.mainloop()
을하지만 오류가 계속 :
Traceback (most recent call last):
File "C:\Python34\lib\tkinter\__init__.py", line 1538, in __call__
return self.func(*args)
File "E:/FinalProject.py", line 10, in crscore
s2grade = float(s2gradefloat.get())
NameError: name 's2gradefloat' is not defined
을 나는 아마 여기에 많은 실수를 만들고있어 실현 이것은 내가 지금까지 가지고있는 것입니다. 누구든지 도와 줄 수 있습니까? 귀하의 계산 기능에
당신은 심지어's2gradefloat'이없는 보여 주었다 코드입니다. 's2grade = float (s2gradef.get())'이라는 줄이's2gradef'를 사전으로 액세스하려고 시도하는'crscore' 안에 있습니다. 그러나 당신은 결코 그런 식으로 선언하지 않았습니다. 그래서 당신은 그것을 수정하기를 원할지도 모릅니다. – idjaw
@ idjaw 프로그래밍에 익숙하지 않은 이유가 무엇인지 알 수 있습니까? –
's2gradef'는 무엇이되어야 하는가? 당신은 그것으로 무언가를하려하고 있습니다, 그래서 여러분은 거기에 어떤 종류의 데이터가 있다고 생각해야합니다. 's2gradef'에 무엇이 있어야합니까? – idjaw