Search code examples
pythonguizero

Python guizero: textBox = [textBox]


OK, I been using guizero for a couple of days but I found a problem that has been perplexing me. Here a simplified version of the code.

from guizero import App, Text, PushButton, Picture, Drawing, TextBox

app = App("Testing")
          
def test():
    global testing
    print(testing)

button = PushButton(app,test, text = "press to test")
button.bg = "red"
button.text_size= 35

tittle = Text(app, "Testing input here")
testing = TextBox(app, text= "" )
app.display()

No matter what the users input into the Textbox, it is always print:

[TextBox] object with text ""

I tried putting testing into an argument in the function test, it comes up with the same thing.

[TextBox] object with text ""

If I don't make an argument in the function or global testing, it makes the same thing, and if I make the textbox before the button, I have the same problem.

Can anyone find a way to work around the problem or to fix this, I'm new to guizero so I have little to an idea what I'm doing


Solution

  • If you want to print the contents of the Text widget then you need to do

    def test():
        global testing
        print(testing.value)
    

    This will get the value of the testing widget rather than the "repr" of the widget.

    Seems like a bit of "bug" in guizero that the description text that is output doesn't update when the value of the widget is updated.

    Issue has been accepted by the developer and a fix has been pushed to a development branch. https://github.com/lawsie/guizero/issues/392