Buttons: Simple User Input
The place_button function can put a button on a GUI4sher project. Place_button requires a string argument which is written on the button. So if you want a button labelled orange you would write place_button(‘orange’).
Of course clicking on the button doesn’t do anything, because the computer does not know what you intend. To make the button do something use the green Edit Clicks button on the right side of the screen.
When you click that button you get a clicks file editor. def orange_button_click(): is used to define what happens when the orange button is clicked. Currently it does pass which means do nothing. But pass can be edited to a different action.
Now this should change the behavior for clicking the button. Now when the button is clicked this is the result.
A more complex button counts how many times it was clicked. We start by creating counter_button whose label shows how many clicks happen. It starts with ‘Not clicked’.
The clicks file defines a count variable and has the count variable increase every time you click. It will show the value of the count variable on the button.
Sometimes one wants to show if the user clicked and allow him if it is a mistake to undo the click. The widget called check does this. It is like a button except it has a visual check on the screen. It has a method called get_check that returns True or False (Boolean values) depending whether it is checked. It also has a method called set_check that allows you to set the check to True or False (and shows it visually).
You can control what happens when you click on the check the same way as you control what buttons do:
This is what it looks like when you click on the check:
Contents