2011-06-21 9 views
-1
from Tkinter import * 

class Application (Frame): 
    def __init__(self, master): 
     Frame.__init__(self, master) 
     self.grid() 
     self.create_widgets() 

    def create_widgets(self): 


     Label(self, text = "Select the last book you read.").grid (row = 0, column = 0, sticky = W) 

     self.choice = StringVar() 

     Radiobutton (self,text = "Nausea by Jean-Paul Sartre",variable = self.choice, 
       value = "Wake up. This is a dream. This is all only a test of the emergency broadcasting system.", 
       command = self.update_text).grid (row = 2, column = 1, sticky = W) 

     Radiobutton (self, 
       text = "Infinite Jest by David Foster Wallace", 
       variable = self.choice, 
       value = "Because an adult borne without the volition to choose the thoughts that he thinks, is going to get hosed ;)", 
       command = self.update_text).grid (row = 3, column = 1, sticky = W) 

     Radiobutton (self, 
       text = "Cat's Cradle by Kurt Vonnegut", 
       variable = self.choice, 
       value = " \"Here we are, trapped in the amber of the moment. There is no why!\" ", 
       command = self.update_text.grid (row = 4, column = 1, sticky = W) 

     self.txt_display = Text (self, width = 40, height = 5, wrap = WORD) 
     self.txt_display.grid (row = 6, column = 0, sticky = W) 


    #There is only one choice value - self.choice. That can be "printed." 

    def update_text(self): 
     message = self.choice.get() 
     self.txt_display.delete (0.0, END) 
     self.txt_display.insert (0.0, message) 

# The Main 
root = Tk() 
root.title ("The Book Critic One") 
root.geometry ("400x400") 

app = Application (root) 
root.mainloop() 

私が失うように見えないself.text_display_delete行に構文エラーが発生し続ける。PythonでのRadioButtonsプログラムのデバッグ

すべての入力をいただければ幸いです。

答えて

2

前の行を見てください - 私は、唯一の閉じ括弧を数え、次の2つ持っている必要がありながら:通常

Radiobutton (self, 
       text = "Cat's Cradle by Kurt Vonnegut", 
       variable = self.choice, 
       value = " \"Here we are, trapped in the amber of the moment. There is no why!\" ", 
       command = self.update_text.grid (row = 4, column = 1, sticky = W)) #<-- Missing that second paren 

を1本のラインがきれいに見える場合は、構文エラーが前の行(複数可)の上にあります、そして99%が欠けているのです。

+2

そのため、私は、複数行のオブジェクト呼び出しを行うときに、閉じ括弧を独自の行に配置する傾向があります。また、彼の他の 'Radiobutton'sに基づいて、それは[...]' self.update_text).grid' [...] – JAB

+0

それを得ました。みんなありがとう! – Louis93

関連する問題