2

I'm simply trying to run the simplest of programs just to make it work, but I keep getting a window with a black background with nothing in it. I've tried changing the background color but nothing seems to work?

from guizero import App, Text, TextBox, PushButton

app = App("Hello world", bg = "white")

welcome_message = Text(app, text="Welcome to my app", size=40, font="Times New Roman", color="white")
my_name = TextBox(app)
update_text = PushButton(app, command=say_my_name, text="Display my name")

app.display()

enter image description here

wjandrea
  • 28,235
  • 9
  • 60
  • 81
  • I edited the title to describe the problem you're having. For reference, see [ask]: "Write a title that summarizes the specific problem". If you'd like to make any further changes, you can [edit] it yourself of course. – wjandrea Dec 06 '21 at 04:19
  • I have the same problem! this issue happens on a mac, when I run the same code on a raspberry pi, I can see the changes. – Marouen Mhiri Feb 28 '22 at 09:16

3 Answers3

0

This could be because you’re using an outdated version of tkinter:

You could check for this in your version of Python3:

>>> import tkinter
>>> tkinter.TkVersion
8.5

If you see 8.5, then you need to install your own version of Python that uses tkinter 8.6 or higher. You could install 3.9.8 or 3.10 from the link above, but if you want newer versions, you could use Homebrew’s Python. Or if you want a different way, pyenv is probably the simplest.

Once you get pyenv set up, it’s as simple as:

pyenv install 3.9.14
pyenv global 3.9.14
pip3 install guizero

Use pyenv install -l to see if there’s a newer version you could use.

kjoonlee
  • 1
  • 1
0

In line 9, don't use keyword text in Pushbutton. I also changed variable in line 6 my_name to text.

from guizero import App, Text, TextBox, PushButton

def say_my_name():
    text.value = 'hello world' 
    
app = App(title='hello world', bg="blue")
welcome_message = Text(app, text="Welcome to my app", size=10, font="Times New Roman", color="white")
text = TextBox(app)
button = PushButton(app, command=say_my_name)

app.display()
toyota Supra
  • 3,181
  • 4
  • 15
  • 19
-1

You're trying to call say_my_name without defining it first. You've also set welcome_message and the apps background to the same color.

from guizero import App, Text, TextBox, PushButton, info
app = App("Hello world", bg = "white")


def say_my_name():
    #Change to do what you want
    #my_name.value gives you the text value of myname after you use the pushbutton  
    app.info("User greeting", "welcome "+my_name.value)


welcome_message = Text(app, text="Welcome to my app", size=40, font="Times New Roman", color="Black")
my_name = TextBox(app)
update_text = PushButton(app, command=say_my_name, text="Display my name")


app.display()
PurpleLlama
  • 168
  • 1
  • 2
  • 14