473,569 Members | 2,691 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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,mas ter):
frame = Frame(master)
frame.pack()

self.button = Button(frame, text = "Quit", fg = "red", command
=frame.quit)
self.button.pac k(side=LEFT)

self.hi_there = Button(frame, text = "Hello", command =
self.say_hi)
self.hi_there.p ack(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:\Documen ts and Settings\INTERN ET\Desktop\hell o2.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 1975
sn****@gmail.co m 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,mas ter): ^^^^^^

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.pac k(side=LEFT)

self.hi_there = Button(frame, text = "Hello", command =
self.say_hi)
self.hi_there.p ack(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:\Documen ts and Settings\INTERN ET\Desktop\hell o2.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
2910
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 a large(ish) XML document but thats probably not important ;-) I'm new to Tkinter so I've started in a fairly random place: the main menu. I...
6
2430
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, master): self.root = master self.master=master self.createWidgets() def createWidgets(): ...
4
3799
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, and I've tried ConsoleEx which does a great job, but still doesn't handle non-character keys like CTRL and the arrow keys. I've read the character...
1
6457
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 called myimage.jpg is inside)
4
1800
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. Here is the code: #start of code from Tkinter import * class DisplayPict(Frame):
2
1409
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 directoy... can u understand my bad english ??? Thanx in advance -- "The best way to predict the future, is to invent it"
0
1414
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 then wanted to start putting some data into it. As you will see, the program is not yet finished but I post what I have so far.
4
1406
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 use of any CacheDependency at all ... what's the problem ?
2
1824
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 months. Anyway, I made a minor change to the code in the console app for an exception that I get from time to time, and now when I test it the web app can...
0
7698
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8122
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7673
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7970
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6284
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5513
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
1
2113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1213
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.