RussianVodka
January 9th, 2007, 08:35 PM
Python with Tkinter. Copied it straight out of the book. Don't think I made any typos. For some reason it's not recognizing the functions. And "app = Application(root)" doesn't work either.
I don't see anything wrong with it.
Here is the code, I bolded the places that get errors:
#Movie Chooser
#Demonstrates check buttons
from Tkinter import *
class Application(Frame):
""" GUI Application for favorite movie types. """
def __init__(self, master):
Frame.__init__(self, master)
self.grid()
self.create_widgets()
def create_widgets(self):
""" Create widgets for movie type choices. """
#Create description label
Label(self,
text = "Choose your favorite movie types"
).grid(row = 0, column = 0, sticky = W)
#Create instruction label
Label(self,
text = "Select all that apply:"
).grid(row = 1, column = 0, sticky = W)
#Create Comedy check button
self.likes_comedy = BooleanVar()
Checkbutton(self,
text = "Comedy",
variable = self.likes_comedy,
command = self.update_text
).grid(row = 2, column = 0, sticky = W)
#Create Drame check button
self.likes_drama = BooleanVar()
Checkbutton(self,
text = "Drama",
variable = self.likes_drama,
command = self.update_text
).grid(row = 3, column = 0, sticky = W)
#Create Romance check button
self.likes_romance = BooleanVar()
Checkbutton(self,
text = "Romance",
variable = self.likes_romance,
command = self.update_text
).grid(row = 4, column = 0, sticky = W)
#Create text field
self.results_txt = Text(self, width = 40, height = 5, warp = WORD)
self.results_txt.grid(row = 5, column = 0, columnspan = 3)
def update_text(self):
""" Update text widget and display user's favorite movie types. """
likes = ""
if self.likes_comedy.get():
likes += "You like comedic movies.\n"
if self.likes_drama.get():
likes += "You like comedic movies.\n"
if self.likes_romance.get():
likes += "You like romantic movies."
self.results_txt.delete(0.0, END)
self.results_txt.insert(0.0, likes)
#Main
root = Tk()
root.title("Movie Chooser")
app = Application(root)
root.mainloop()
And here is the messages I get when I run it:
Traceback (most recent call last):
File "movie_chooser.py", line 70, in ?
app = Application(root)
File "movie_chooser.py", line 11, in __init__
self.create_widgets()
File "movie_chooser.py", line 30, in create_widgets
command = self.update_text
AttributeError: Application instance has no attribute 'update_text'
I don't see anything wrong with it.
Here is the code, I bolded the places that get errors:
#Movie Chooser
#Demonstrates check buttons
from Tkinter import *
class Application(Frame):
""" GUI Application for favorite movie types. """
def __init__(self, master):
Frame.__init__(self, master)
self.grid()
self.create_widgets()
def create_widgets(self):
""" Create widgets for movie type choices. """
#Create description label
Label(self,
text = "Choose your favorite movie types"
).grid(row = 0, column = 0, sticky = W)
#Create instruction label
Label(self,
text = "Select all that apply:"
).grid(row = 1, column = 0, sticky = W)
#Create Comedy check button
self.likes_comedy = BooleanVar()
Checkbutton(self,
text = "Comedy",
variable = self.likes_comedy,
command = self.update_text
).grid(row = 2, column = 0, sticky = W)
#Create Drame check button
self.likes_drama = BooleanVar()
Checkbutton(self,
text = "Drama",
variable = self.likes_drama,
command = self.update_text
).grid(row = 3, column = 0, sticky = W)
#Create Romance check button
self.likes_romance = BooleanVar()
Checkbutton(self,
text = "Romance",
variable = self.likes_romance,
command = self.update_text
).grid(row = 4, column = 0, sticky = W)
#Create text field
self.results_txt = Text(self, width = 40, height = 5, warp = WORD)
self.results_txt.grid(row = 5, column = 0, columnspan = 3)
def update_text(self):
""" Update text widget and display user's favorite movie types. """
likes = ""
if self.likes_comedy.get():
likes += "You like comedic movies.\n"
if self.likes_drama.get():
likes += "You like comedic movies.\n"
if self.likes_romance.get():
likes += "You like romantic movies."
self.results_txt.delete(0.0, END)
self.results_txt.insert(0.0, likes)
#Main
root = Tk()
root.title("Movie Chooser")
app = Application(root)
root.mainloop()
And here is the messages I get when I run it:
Traceback (most recent call last):
File "movie_chooser.py", line 70, in ?
app = Application(root)
File "movie_chooser.py", line 11, in __init__
self.create_widgets()
File "movie_chooser.py", line 30, in create_widgets
command = self.update_text
AttributeError: Application instance has no attribute 'update_text'