2017-05-28 10 views
1

私はチュートリアルを通して学んだことのいくつかを組み合わせようとしているPythonのnoobです。 guizeroとGUIを具体的に作っています。guizero/tkinter PushButton NameError from guizero PushButton.py

私は、player_nameという名前のTextBoxオブジェクトとcreate_storyというPushButtonオブジェクトを作成しました。私の目標は、テキストボックスが空の場合はボタンを無効にし、何かがボックスに入力されたらボタンを有効にすることです。

guizeroドキュメントリスト ")(有効" とプッシュボタンに添付メソッドとして ")(無効" が、詳細には触れません。これまでhttps://lawsie.github.io/guizero/pushbutton/#methods

全コード:

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() 

エラー:

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 

答えて

1

おめでとうございます、あなたはバグを発見しました。パッケージに記載されている通り:

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

guizeroがまだアルファバージョンのままであるため、それでもバグがあります。 https://github.com/lawsie/guizero/commit/236064b8781c298a87954775daed65cb384d04f4(実際には、間違いはありませんでした。実際にはlawuch mergedプルリクエストがあります)hereが表示されているので、その人はtkinter.DISABLEtkinter.ENABLEをインポートするのを忘れていました。

ここで問題を報告することができます:https://github.com/lawsie/guizero/issuesうまくいけば、すぐに変更することができます。これは非常に簡単な修正です。