469,949 Members | 2,183 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,949 developers. It's quick & easy.

Tkinter app=App(root) problem

This is my first day working with Tkinter. I'm using python2.3 on
WindowsXP. I found this program and entered it.

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()

When I run the code in IDLE I get the initial frame but no buttons with
the following error:

Traceback (most recent call last):
File "C:\Documents and Settings\INTERNET\Desktop\hello2.py", line 18,
in ?
app = App(root)
TypeError: this constructor takes no arguments

I have also tried to save the program as with a pyw extension. Nothing
happens when I try to run it with that extension.

Jul 19 '05 #1
1 1840
sn****@gmail.com wrote:
This is my first day working with Tkinter. I'm using python2.3 on
WindowsXP. I found this program and entered it.

from Tkinter import *

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

This should be __init__ (the underscores should be doubled). Python
"magic methods" are all named in this way.
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()

When I run the code in IDLE I get the initial frame but no buttons with
the following error:

Traceback (most recent call last):
File "C:\Documents and Settings\INTERNET\Desktop\hello2.py", line 18,
in ?
app = App(root)
TypeError: this constructor takes no arguments

I have also tried to save the program as with a pyw extension. Nothing
happens when I try to run it with that extension.

That's not strictly true. Nothing *appears* to happen, because the same
error message is produced but there's no windows console to display it in.

regards
Steve
--
Steve Holden +1 703 861 4237 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/

Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Richard Lewis | last post: by
6 posts views Thread by William Gill | last post: by
4 posts views Thread by Chris Williams | last post: by
1 post views Thread by Joel Leong | last post: by
4 posts views Thread by john.orlando | last post: by
2 posts views Thread by Hector Y. Martinez | last post: by
reply views Thread by Svenn Bjerkem | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.