Mailing List Archive

Type Error when running Tkinter tutorial's hello2.py example
Hi! I going through the draft Tkinter tutorial from Pythonware.com, and
I'm trying to run its hello2.py example program:-

Example: File: hello2.py

from Tkinter import *

class App:

def _init_(self, master):
frame = Frame(master)
frame.pack()

self.button = Button(frame, text="QUIT", fg="red",
command=frame.quit)
self.button.pack(side=LEFT)

self.hi_there = Button(frame, text="Hello", command=self.say_hi)
self.hi_there.pack(side=LEFT)

def say_hi(self):
print "Hi there, everyone!"

root = Tk()
app = App(root)
root.mainloop()

However, whenever I try to run the above program, I get the following
error message:-

File "F:\PALRES~1\PALDIR~1\DEVELO~1\test.py", line 19, in ?
app = App(root)
TypeError: this constructor takes no arguments

Does anybody know what's wrong?

I'm using Python ver 1.5.2 on Win 95.


--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---
Type Error when running Tkinter tutorial's hello2.py example [ In reply to ]
On Thu, May 27, 1999 at 10:27:16AM +0000, tlng@phileo.com.my wrote:


> Hi! I going through the draft Tkinter tutorial from Pythonware.com, and
> I'm trying to run its hello2.py example program:-

> class App:
> def _init_(self, master):

You need
def __init__(self, master):

Double underscores ('underbars') on each side of 'init'. This goes for all
the magically-called functions, by the way.

> File "F:\PALRES~1\PALDIR~1\DEVELO~1\test.py", line 19, in ?
> app = App(root)
> TypeError: this constructor takes no arguments

--
Thomas Wouters <thomas@xs4all.net>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!