473,387 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 1967
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Richard Lewis | last post by:
Hi there, I've just started my first project with Tkinter. I've already coded all the data handling classes and have a nice interface to work with (it happens to be a wrapper around the DOM of...
6
by: William Gill | last post by:
A short while ago someone posted that(unlike the examples) you should use Tk as the base for your main window in tkinter apps, not Frame. Thus : class MyMain(Frame): def __init__(self,...
4
by: Chris Williams | last post by:
Hi... I'm trying to find some code samples that will show me how to capture non-character keypresses in a console app. I've tried the standard stuff, such as console.read and console.readline,...
1
by: Joel Leong | last post by:
I wonder how I can refer or get my web app root directory without using code behind. Here is my scenario. I created the folders below --WebAppRoot ----common ----img (assume a file...
4
by: john.orlando | last post by:
Hello, I'm a newbie to Python (literally, within the last two weeks), and I am playing around with Tkinter to build some simple GUIs. I am attempting to build a simple class that displays a GIF. ...
2
by: Hector Y. Martinez | last post by:
Hello: I'm developing an app, with a plugins system, and I have a folder, plugins, thats in the same directory with the app, then a need a function or something that tell me what is the App root...
0
by: Svenn Bjerkem | last post by:
Hi, Armed with Programming Python 3rd Edition and Learning Python 2nd edition I try to write an application which I at first thought was simple, at least until I was finished with the GUI and...
4
by: Khafancoder | last post by:
Hi guys, i keep many items in cache such as onlineusers and ... recently i build a page which create tempfolders in webapplication root dir but i findout that it invalidate cache and i hadn't...
2
by: stoogots2 | last post by:
Ok, this console app that I wrote has an endpoint that listens on a TCP port. A web application sends requests to it. Both of these have been running successfully in production for the last 6...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.