python - PYTHON FUNCTIONS UnboundLocalError:分配前引用的局部变量“值”
问题描述
我想携带一个价值,无论我做什么都不会。这只是代码片段,但我希望这里有足够的,谢谢
def create_window2(value):
print(value)
window2 = Tk()
window2.title("Choose Quantity")
L1 = Label(window2, text="How many ml of"+value+"would you like?")
S1 = Spinbox(window2, from_=0, to=10000000)
button1 = Button(window2, text='continue', command= lambda: create_window3(value,S1.get()))
#listbox.insert(END, S1,"bottles will be scheduled to be made once equipment has been found")
L1.pack()
S1.pack()
button1.pack()
def nextup(up):
if up == '1':
value = "Pilsner"
elif up == '2':
value = "Dunkel"
elif up == '3':
value = "Red Helles"
print(value)
create_window2(value)
def sel(var):
selection = str(var.get())
nextup(selection)
def chooser():
ch_beer = Tk()
var = IntVar()
R1 = Radiobutton(ch_beer, text="Pilsner", variable=var, value=1,
command=lambda:sel(var))
R1.pack( anchor = W )
R2 = Radiobutton(ch_beer, text="Dunkel", variable=var, value=2,
command=lambda:sel(var))
R2.pack( anchor = W )
R3 = Radiobutton(ch_beer, text="Red Helles", variable=var, value=3,
command=lambda:sel(var))
R3.pack( anchor = W)
ch_beer.mainloop()
此处给出错误 print(value) UnboundLocalError: local variable 'value' referenced before assignment
解决方案
推荐阅读
- python - 或在 flask_SQLAlchemy 中查询
- java - Java 服务器-客户端连接重置
- database - 使用多个数据库全新构建应用程序
- elasticsearch - elasticsearch-rest-high-level-client:6.5.0 BulkRequest 不再工作
- php - 使用 Ajax 传递 PHP var
- sql - vb.net 和 sql 数据库应用程序安装程序
- c# - .NET 获取 AD 计算机的完整属性列表(以匹配 Powershell Get-ADComputer API)
- css - 未能将边框半径样式应用于表格
- angular - NgxPermissions hasPermission 检查在 Angular 6 中的 Observable 方法中
- java - 读取数据时套接字损坏或超时