JSchub
JSchub

Reputation: 23

guizero / tkinter PushButton NameError from guizero PushButton.py

I'm a Python noob trying to combine a few of the things I've learned through tutorials; making a GUI with guizero specifically.

I've created a TextBox object called player_name and a PushButton object called create_story . My goal is to disable the button if the text box is empty, and enable the button when something has been typed into the box.

The guizero documentation lists "enable()" and "disable()" as methods attached to PushButton, but doesn't go into detail: https://lawsie.github.io/guizero/pushbutton/#methods

Full code so far:

import random
from guizero import App, Text, TextBox, PushButton, ButtonGroup, Combo, Box

def print_story():
    print("Button Pressed")

app = App(title="Visual Adventure", width=550, height=400,)

hello_message = Text(app, text="Hello, Traveler", size=20, color="red")
story_message = Text(app, text="Would you like to hear a tale?", size=14, color="black")

# organize into box with grid
selections = Box(app, layout="grid")

# text for questions
name_ques = Text(selections, text="What is your name?", size=10, color="black", grid=[0,0], align="left")
gender_ques = Text(selections, text="Boy or a girl?", size=10, color="black", grid=[0,2], align="left")
day_ques = Text(selections, text="What day is it?", size=10, color="black", grid=[0,4], align="left")

# text for grid padding
pad1 = Text(selections, text="        ", size=10, grid=[0,1], align="left")
pad2 = Text(selections, text="        ", size=10, grid=[0,3], align="left")

# interactive objects
player_name = TextBox(selections, width=15, grid=[1,0], align="top")
player_gender = ButtonGroup(selections, options=[ ["Boy", "He"], ["Girl", "She"] ], selected="He", horizontal=True, grid=[1,2], align="top")
day_set = Combo(selections, options=["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"], selected="Monday", grid=[1,4], align="top")

create_story = PushButton(app, command=print_story, text="Tell me!")

if not player_name.get():
    create_story.disable()
elif player_name.get():
    create_story.enable()

app.display()

The error:

Traceback (most recent call last):
  File "/home/pi/Desktop/python/VisualAdventure.py", line 32, in <module>
    create_story.disable()
  File "/usr/local/lib/python3.4/dist-packages/guizero/PushButton.py", line 59, in disable
    self.config(state=DISABLED)
NameError: name 'DISABLED' is not defined

Upvotes: 1

Views: 1096

Answers (2)

Bobfishcake
Bobfishcake

Reputation: 1

Get around it using: create_story["state"] = "disabled" etc

Upvotes: 0

Taku
Taku

Reputation: 33714

Congratulations, you have found a bug. As the package stated:

This is a pre-release version, so there may be bugs and features may change.

As in that there is still bugs to be found since guizero is still in alpha version. The specific commitment that made that mistake was: https://github.com/lawsie/guizero/commit/236064b8781c298a87954775daed65cb384d04f4 (actually, there wasn't any mistakes made there, it's actually when lawsie merged the pull-request).As you can see here, that person forgot to import tkinter.DISABLE and tkinter.ENABLE.

You can report the issue here: https://github.com/lawsie/guizero/issues hopefully they change it soon, since it's a extremely easy fix.

Upvotes: 1

Related Questions