[英]How to the output of function on_click
I am planning to return the value of gameMode because I would like to use the output of gameMode being easy medium or hard for a game I am doing but there is always a name error.我打算返回 gameMode 的值,因为我想使用 gameMode 的 output 对于我正在做的游戏来说是简单的中等或困难的,但总是有一个名称错误。 Is there any way to solve this?
有没有办法解决这个问题? picture of the error: enter image description here
错误图片:在此处输入图片描述
from ipywidgets import Button, HBox
Modes = ['Easy', 'Medium','Hard']
switch = [Button(description=name) for name in Modes]
combined = HBox([items for items in switch])
def upon_clicked(btn):
gameMode=btn.description.lower()
for n in range(len(Modes)):
switch[n].style.button_color = 'gray'
btn.style.button_color = 'pink'
for n in range(len(Modes)):
switch[n].on_click(upon_clicked)
display(combined)
gameMode
You need to return a value from the on_click handler or be able to set an attribute.您需要从 on_click 处理程序返回一个值,或者能够设置一个属性。 Check out Return output of the function executed 'on_click'
查看执行“on_click”的 function 的返回 output
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.