Reputation: 121
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()
Upvotes: 2
Views: 397
Reputation: 4543
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()
Upvotes: 0
Reputation: 1
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.
Upvotes: 0
Reputation: 178
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()
Upvotes: -1