Я написал простую программу, импортирующую Tkinter, чтобы играть с Radio Buttons. Я нахожу, что получаю ошибки в очень, очень странных местах.Отладка программы RadioButtons в 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()
Я, кажется, получаю ошибки в очень странных местах. Один пришел в знак «=» в атрибуте «Ярлык», и когда я изменил его на «==», когда я играл, следующий пришел в переменную часть атрибутов RadioButton.
Любая помощь была бы принята с благодарностью. Я не смогу сразу ответить, так как мне нужно немного поработать, но если вы заметите ошибки, пожалуйста, дайте мне знать.
Спасибо! Я изменил его, но я все еще получаю еще одну непонятную синтаксическую ошибку с подсветкой «Я». Здесь: http://stackoverflow.com/questions/6427245/debugging-radiobuttons-program-in-python – Louis93
@ Louis93: Обновлено. – Bryan
жаль быть громоздким. Я обновил код и исправил все ошибки, которые я знаю, включая ошибки с переменными выбора. Добавил себя к параметру создания виджетов и исправил опечатку в txt_display. Синтаксическая ошибка все же появляется в том же месте: выделяется «self.txt_display» и «self». – Louis93