bensimmo
Posts: 1555
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

guizero - refresh text display

Mon Jun 12, 2017 2:45 pm

After having a play with guizero, it looked like the perfect thing we are looking for to display simple information updates.

But we (well I) cannot figure out how to refresh the display easily.
Everything seems to need to have no loops and be initiated by push buttons or sliders.

Am I missing something?

The use of app.display seems to kill off a program.

For example.

-Import app and text from guizero
-Add a textbox.

-Display a value in textbox
-LOOP
-- Add one to the value
-- update text box with .set


IF app.display is in the loop, it will halt at that and doesn't loop.
If it's before the loop it stops there and doesn't go past it and into the loop
If it after the loop, nothing gets updated as it has not yet created the GUI.*

So how do I do this with guizero
Create a display with text boxes.

Collect data values from a sensor
Show value in the text boxes
And repeat


(It's part of a bigger logging program based around the SenseHat Datalogging code, but this simple loop is the basis, get data, display data, save data...).

*Given it never leaves the while true: , app.display would never be run.

scotty101
Posts: 2221
Joined: Fri Jun 08, 2012 6:03 pm

Re: guizero - refresh text display

Mon Jun 12, 2017 4:16 pm

Correct. You should not make use of infinite/long loops within guizero (or tkinter*) programs

The guizero examples show how to make use of a 'timer callback' to call a function again and again (as if in a loop). This example also includes a "read_sensor" function so it should help you out a lot.
https://github.com/lawsie/guizero/blob/ ... example.py
Code copied here for clarity of this answer

Code: Select all

from guizero import *
import random


def read_sensor():
    return random.randrange(3200, 5310, 10) / 100


def update_label():
    text.set(read_sensor())
    # recursive call
    text.after(1000, update_label)


if __name__ == '__main__':
    app = App(title='Sensor Display!',
              height=100,
              width=200,
              layout='grid')

    title = Text(app, 'Sensor value:', grid=[0, 0])
    text = Text(app, "xx", grid=[1, 0])

    text.after(1000, update_label)
    app.display()
You create a function (in the example called update_label) and you use the after method to schedule this function to be called periodically.
app.display should only be called once in a program and any command after that won't be run until the app is quit by the user.

*guizero is a wrapper on top of tkinter
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

bensimmo
Posts: 1555
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: guizero - refresh text display

Mon Jun 12, 2017 7:40 pm

Many thanks, I've been using the main documentation https://lawsie.github.io/guizero/about/ here and it's certainly not clear. No mention of that at all.
What you given shows me what I need to attempt doing.

Microsoft make GUI programming so much easier.

scotty101
Posts: 2221
Joined: Fri Jun 08, 2012 6:03 pm

Re: guizero - refresh text display

Mon Jun 12, 2017 10:01 pm

Guizero is new. Give it a chance.

It makes it much easier for beginners.
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

B.Goode
Posts: 3964
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: guizero - refresh text display

Tue Jun 13, 2017 5:35 am

Version

guizero is currently version 0.3.3

This is a pre-release version, so there may be bugs and features may change.
Maybe polite constructive feedback to the developer concerning the perceived deficiencies in the documentation would be appropriate?

https://github.com/lawsie/guizero/issues

bensimmo
Posts: 1555
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: guizero - refresh text display

Tue Jun 13, 2017 6:31 am

I wasn't having a go, just mentioning the documentation didn't mention it.
(and yes I do feedback on git if I think it's needed, but the documentation is not linked)

I had seen guizero crop up before (I've mentioned it before), though given it had hit MagPi & the website https://www.raspberrypi.org/learning/ge ... worksheet/ I figured it must have hit the can now be used level. (No mention in MagPi or the website it is all pre release ;-))
Which it can :-)
But for what I wanted nothing but the small demo on github gave hint of how to actually use it. It's​ just a change of thinking from the Python way they have been teaching on the site.
Job for today, try and get it working and then see if the kids can understand it.

Hopefully it can compliment gpiozero well :-)

scotty101
Posts: 2221
Joined: Fri Jun 08, 2012 6:03 pm

Re: guizero - refresh text display

Tue Jun 13, 2017 8:20 am

A link to the documentation is provided on the GitHub readme page.

https://github.com/lawsie/guizero/blob/master/README.md
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

bensimmo
Posts: 1555
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: guizero - refresh text display

Tue Jun 13, 2017 8:29 am

scotty101 wrote:A link to the documentation is provided on the GitHub readme page.

https://github.com/lawsie/guizero/blob/master/README.md
but not vice versa or any specific way to comment on the documentation.
compare that to gpiozero
https://gpiozero.readthedocs.io


It'll come along though as people start using it.

It's a brilliant idea

User avatar
lawsie
Posts: 11
Joined: Thu Jul 17, 2014 6:02 pm

Re: guizero - refresh text display

Mon Jun 19, 2017 7:57 am

The entire documentation resides in the exact same github repo at https://github.com/lawsie/guizero/tree/master/docs. You're very welcome to create a pull request to docs-src (https://github.com/lawsie/guizero/tree/master/docs-src ) if you think something needs updating, and I will merge it and regenerate the docs as necessary.

bensimmo
Posts: 1555
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: guizero - refresh text display

Mon Jun 19, 2017 11:24 am

lawsie wrote:The entire documentation resides in the exact same github repo at https://github.com/lawsie/guizero/tree/master/docs. You're very welcome to create a pull request to docs-src (https://github.com/lawsie/guizero/tree/master/docs-src ) if you think something needs updating, and I will merge it and regenerate the docs as necessary.
That's another thing I've got to get around to learning about :-)
I can ask questions on github so far (as you may know :oops: )

B.Goode
Posts: 3964
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: guizero - refresh text display

Mon Jun 19, 2017 8:21 pm

bensimmo wrote:
lawsie wrote:The entire documentation resides in the exact same github repo at https://github.com/lawsie/guizero/tree/master/docs. You're very welcome to create a pull request to docs-src (https://github.com/lawsie/guizero/tree/master/docs-src ) if you think something needs updating, and I will merge it and regenerate the docs as necessary.
That's another thing I've got to get around to learning about :-)
I can ask questions on github so far (as you may know :oops: )

Those nice Raspberry Pi Foundation people have even provided a Learning Resource (tutorial) that explains just how to do that...
https://www.raspberrypi.org/learning/ge ... -with-git/

bensimmo
Posts: 1555
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: guizero - refresh text display

Tue Jun 20, 2017 7:12 am

B.Goode wrote:
bensimmo wrote:
lawsie wrote:The entire documentation resides in the exact same github repo at https://github.com/lawsie/guizero/tree/master/docs. You're very welcome to create a pull request to docs-src (https://github.com/lawsie/guizero/tree/master/docs-src ) if you think something needs updating, and I will merge it and regenerate the docs as necessary.
That's another thing I've got to get around to learning about :-)
I can ask questions on github so far (as you may know :oops: )

Those nice Raspberry Pi Foundation people have even provided a Learning Resource (tutorial) that explains just how to do that...
https://www.raspberrypi.org/learning/ge ... -with-git/
It's terrible isn't it, they make it easy for us :-)

Return to “Python”

Who is online

Users browsing this forum: California and 11 guests