if checked_a==1:
dulj_a=math.sqrt(stranica_1_duljina **2 - stranica_2_duljina**2) #riješiti str_a
str_dulj_a= str(dulj_a)
ispis_dulj_a=Label(window, text= dulj_a , font=("Arial", 30,"bold"), bg="lightblue")
ispis_dulj_a.place(x=1250,y=800)
def ispis_a():
ispis_a_text=Label(window, text="Duljina stranice a iznosi" + str_dulj_a , font=("Arial", 30,"bold"), bg="lightblue")
ispis_a_text.place(x=1200,y=800)
错误:
File "C:\Users\Korisnik\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
File "G:\Python-programi\Pitagora v2.py", line 159, in ispis_a
ispis_a_text=Label(window, text="Duljina stranice a iznosi" + str_dulj_a , font=("Arial", 30,"bold"), bg="lightblue")
NameError: name 'str_dulj_a' is not defined
答案 0 :(得分:0)
由于checked_a
是一个按钮,如果启用,它将等于1
。如果该按钮关闭,该怎么办,您还可以在调用str_dulj_a
之前在代码行中的其他地方定义ispis_a
喜欢
if checked_a==1:
dulj_a=math.sqrt(stranica_1_duljina **2 - stranica_2_duljina**2)
#riješiti str_a
str_dulj_a= str(dulj_a)
else:
str_dulj_a = "some string"
或在开始时进行初始化
str_dulj_a = "init string"
if checked_a==1:
dulj_a = math.sqrt(stranica_1_duljina **2 - stranica_2_duljina**2)
str_dulj_a = str(dulj_a)
ispis_dulj_a=Label(window, text= dulj_a , font=("Arial", 30,"bold"), bg="lightblue")
ispis_dulj_a.place(x=1250,y=800)
def ispis_a():
# Now you have a defined string of `str_dulj_a`
ispis_a_text=Label(window, text="Duljina stranice a iznosi" + str_dulj_a , font=("Arial", 30,"bold"), bg="lightblue")
ispis_a_text.place(x=1200,y=800)