Entering Text
Sometimes buttons are not enough. You want the user to enter information like their name or a number. In that case GUI4sher uses the entry widget. The place_entry function puts a rectangle that the user can type in. Place_entry requires an integer argument that is how many characters wide the rectangle is. So if the user writes place_entry(7) it will place a rectangle with room for 7 characters. The user can type more characters but only 7 will be visible.
Its good to label your entry so the user can tell what to enter in the entry.
In the clicks file you can edit the function with the entry name followed by _return. This function will happen when the user hits the enter (sometimes called return) key when typing the entry.
You can use the get_text method to get what the user typed. You can also use other methods mentioned previously like set_fill, get_fill, set_font, get_font and so on. In the example below the name_entry_return function was set up to say hello to the user when he enters his name and hits hello.
The text widget allows the user to enter or view multiline text. You add a text widget with the place_text function. The function has 2 arguments for the number of characters in a line and the number of lines. There is no function in the click file for that, if you want to respond to the text the user enters you need to add a button. You can do things with the text using the get_text method. The example below finds if the users name is in the text.
The first few times I wrote this I used elif index = len(name) -1 instead of elif index == len(name) – 1
You can se that GUI4sher reported this error and the line it occurred on.
/
Another error was reported since name_text was used instead of words_text. All such errors are reported in red. Once that error was corrected the project could find names and not find names in it.
Once you created a complex project you might want to share it with friends or submit it as an assignment. You can use the Make App button (green button on the right side) to create a python app.
The first thing that happens when you click make app is that it requests a name and location for the app file.
The app has no shell but it does the same thing as the GUI4sher project:
Contents