-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
args for widgets that support command #499
Comments
tbh, guizero moved away from the use of
e.g. if you wanted to send 2 values to sliders command, the slider value plus an index, you could do this: from guizero import App, Slider, TextBox
def slider_changed(slider_value, index):
textbox.value = str(slider_value) + ":" + str(index)
app = App()
slider = Slider(app, command=lambda: slider_changed(slider.value, 1))
textbox = TextBox(app)
app.display() |
A lambda is a reasonable approach. But I would suggest updating the docs to say you can do that. Currently says "The name of a function to call when the slider value is changed". some example code as you do in your response would also be very useful. If you want to consider this closed, I have no problem with that. |
Lets leave it open until we agree what to do. I am all for: . updating the docs to reflect the use of lambda when passing arguments to callbacks |
Sorry, I never replied to this! I guess lambda is more universal, but the reason I originally added |
The PushButton widget has an args parameter that can be used to send arguments to the command function. The slider widget, for example, also supports a command function, so it would make sense if it also supports args.
An example use case would be for a list of similar things, each needing a slider and a button. These could be added in a loop. Each button can use the same command function, and by giving the iterator index in the args the button can be identified. I want to be able to do tat with the slider.
Also applies to ListBox, TextBox, CheckBox, Combo.
The text was updated successfully, but these errors were encountered: