Today I started using Tkinter with Python 2.4, I have been reading tutorials, and running example programs and looking at the code used, but I have a small problem when I run code of my own.
Code:
from Tkinter import *
import tkMessageBox
class Application(Frame):
def __init__( self, master):
Frame.__init__( self, master )
self.grid()
self.create_widget()
def create_widget( self ):
self.bttn = Button( self )
self.bttn["text"] = "Click Me!"
self.bttn["command"] = self.respond_to_click
self.bttn.grid()
def respond_to_click( self ):
tkMessageBox.showinfo( title = "Response", message="You clicked me!")
if __name__ == '__main__':
root = Tk()
root.title( "Button Response" )
root.geometry( "200x100" )
myApp = Application(root)
root.mainloop()
I get an error of:
Code:
Traceback (most recent call last):
File "/****/****/****/*****/test.pyw", line 28, in -toplevel-
myApp = Application(root)
File "/****/****/****/*****/test.pyw", line 9, in __init__
self.create_widget()
AttributeError: Application instance has no attribute 'create_widget'
If I take out the "root" in "myApp = Application(root)" I get this error:
Code:
Traceback (most recent call last):
File "/****/****/*****/*****/test.pyw", line 28, in -toplevel-
myApp = Application()
TypeError: __init__() takes exactly 2 arguments (1 given)
Any ideas?
****Error messages edited taking out file path****