簡體   English   中英

在Python中調試RadioButtons程序

[英]Debugging RadioButtons program in Python

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行中不斷收到語法錯誤,這似乎並不會丟失。

任何投入將不勝感激。

看看上一行-我只算了一個右括號,而您應該有兩個:

 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

通常,如果一行看起來很干凈,則語法錯誤在前一行上,並且有99%的時間是缺少的括號。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM