Hi I am a total beginner going through the guizero tutorials and I have gotten the scrollphat hd to display my message when i click the button. As you can see i have placed in the TextBox function from guizero to type in text which i hope to display on the scrollphat hd but I am at a standstill as the . set and .get functions in the tutorial are getting me nowhere. Any help would be great!
The ones documented here? https://lawsie.github.io/guizero/textbox/
In your case, surely
message.get() is all you need to retrieve the textbox value?
Thanks for the help, ok i solved the problem but now i am looking to have the clear button clear out the info but it will not activate?
This is where everything gets a little tricky.
In brief; your
scroll_name() function is running a
while True loop which, if GUI Zero is single-threaded, will block any further functions from running.
Once your program hits the top of that
while True, all other input will be unresponsive until the loop is broken.
There are ways to fix this, but right now I’d focus on just displaying a short name/word and clearing it, without any looping or animation.
In order to do anything fancy, you will need to:
- Spawn a thread to exclusively handle displaying things on the Scroll pHAT HD
- Find some way of passing messages to that thread, to tell it what to do next
- Change your UI handlers so that they send messages and return without blocking (running for a long time, or indefinitely)
There’s a good pattern for this buried in the Twitter Hashtag example, but it may not be easy to extract: https://github.com/pimoroni/scroll-phat-hd/blob/master/examples/twitter-hashtag.py
This is a very common pitfall with GUI programming- unless you properly architect your code, button actions will end up “blocking” and cause the UI to be sluggish at best and completely unresponsive at worst.
Thanks for all the helpful info, appreciate it! I will look into that twitter code to see what I can find. To run this script so it will not open in thonny or IDLE is it best to use something like freeze or py2exe?
That’s a good question- I’ve never packaged up a Python script as an executable before.
If you’re just targeting Raspbian then I suspect some standard packaging methods might be overkill. It might suffice to just add a
.desktop file in
/usr/share/applications/ with the following content:
[Desktop Entry] Type=Application Encoding=UTF-8 Name=Scroll pHAT GUI GenericName=Scroll pHAT GUI Comment=My python script Exec=/home/pi/mypythonscript.py Icon=/usr/share/pixmaps/some-icon.png Categories=Utility Terminal=false
/home/pi/mypythonscript.py is just a Python script that’s made executable with
chmod +x mypythonscript.py and has the line
#!/usr/bin/env python as the first line.
Great, i’ll give that a try, thanks so much!