473,575 Members | 3,507 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Error: unbound method in Tkinter class

I am trying to structure a Tkinter application with classes instead of
just with simple functions, but I'm not sure how to call methods from my
main class.

My main class is packetstreamApp (). Within that class I call various
methods, including drawGUI() and authorizeDump() . My problem comes when
I try to call authorizeDump from the Tkinter menu. Here is the code that
calls authorizeDump() :

self.packetmenu .add_command(la bel="Start Network Monitor",
command=packets treamApp.author izeDump())

Here is the code for authorizeDump() :

def authorizeDump(s elf):
##do stuff here

And here is the error message that comes when I try to call authorizeDump() :

Traceback (most recent call last):
File "/Users/kevin/Programming/packetstream/packetstream-classes.py",
line 257, in <module>
app = packetstreamApp ()
File "/Users/kevin/Programming/packetstream/packetstream-classes.py",
line 19, in __init__
self.drawGUI()
File "/Users/kevin/Programming/packetstream/packetstream-classes.py",
line 49, in drawGUI
self.packetmenu .add_command(la bel="Start Network Monitor",
command=packets treamApp.author izeDump())
TypeError: unbound method authorizeDump() must be called with
packetstreamApp instance as first argument (got nothing instead)

I don't know how to interpret this error message, and so can't implement
a fix. Can anyone shed light on what I'm doing wrong?

Thanks.

--
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
Dec 9 '06 #1
2 1957
Kevin Walzer wrote:
I am trying to structure a Tkinter application with classes instead of
just with simple functions, but I'm not sure how to call methods from my
main class.

My main class is packetstreamApp (). Within that class I call various
methods, including drawGUI() and authorizeDump() . My problem comes when
I try to call authorizeDump from the Tkinter menu. Here is the code that
calls authorizeDump() :

self.packetmenu .add_command(la bel="Start Network Monitor",
command=packets treamApp.author izeDump())
If that code is inside a method of packetstreamApp :

self.packetmenu .add_command(la bel="...", command=self.au thorizeDump)

i. e. you have to pass a bound method (a method that knows about "its"
instance) and you must not call authorizeDump here (no trailing '()').

Of course I'm only guessing...

Peter
Dec 9 '06 #2
Kevin Walzer wrote:
I am trying to structure a Tkinter application with classes
instead of just with simple functions, but I'm not sure how to
call methods from my main class.

My main class is packetstreamApp ().
I don't think so -- packetstreamApp () would be an (unbound)
instance. packetstreamApp without parentheses is the class.
Within that class I call various methods, including drawGUI() and
authorizeDump() . My problem comes when I try to call authorizeDump
from the Tkinter menu. Here is the code that calls
authorizeDump() :

self.packetmenu .add_command(la bel="Start Network Monitor",
command=packets treamApp.author izeDump())
[...]
TypeError: unbound method authorizeDump() must be called with
packetstreamApp instance as first argument (got nothing instead)
Problem here: You call an instance method without having created an
instance (it's not bound to any instance, thus it's an unbound
method).

One fix is to first create an instance and then access the method:

1.
psApp = packetstreamApp ()

2.
test = psApp.authorize Dump()
OR
test = packetstreamApp .authorizeDump( psApp)

Regards,
Björn

P.S.: Beware: If you want to pass functions like above, leave out
the parentheses or they will be executed immediately and their
return value will be passed.

--
BOFH excuse #389:

/dev/clue was linked to /dev/null

Dec 9 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
5964
by: Josh | last post by:
Caution, newbie approaching... I'm trying to come up with a very simple Tkinter test application that consists of a window with a drop-down menu bar at the top and a grid of colored rectangles filling the remainder of the window. Mind you, this is a contrived test application to help me understand Tkinter and Python, not an actual...
2
4732
by: Fuzzyman | last post by:
I've written a CGI proxy that remotely fetches web pages. I use the urlopen function in CLientCookie which replaces (and ultimately uses) the urlopen function in urllib2. What I'd like to do is give a more useful message to the user when the page fetch fails. My understanding was that a URLError exception had a 'code' attribute which was...
5
8222
by: NB | last post by:
Hi In my 2 years with Access I have never seen this, now it makes me mad In an unbound form frmTH I have a frmList which is a continous form In its on current event, I synch 4 of its fields with 4 unbound textboxes on the parent form Me.parent!txtLink1 = Me!field1 Me.parent!txtLink2 = Me!field2
2
1804
by: Susan Bricker | last post by:
I went back to read my post and found an error in my description ... here is the post, again, corrected: The following error: "The current field must match the join key '?' in the table that seves as t the 'one' side of one-to-many relationship. Enter a record in the 'one' side table with the desired key value, and then make the entry...
18
3779
by: TORQUE | last post by:
Hi, Im wondering if anyone can help me with a problem. I have a form with more than 50 unbound fields. Some of the fields will be blank from time to time. This seems to be where im having trouble. I have tried keeping some of the fields bound and when I use the save button it has been saving as 2 different records. This is unacceptable. ...
2
2602
by: brent.chambers | last post by:
I wrote a small class today at work playing with sockets in command line windows. When attempting to call the handle function, I get a TypeError. "Unbound method handle() must be called with connection instance as first argument (got nothing instead). Any suggestions would be greatly appreciated. Thanks! -chase
14
3019
by: 7stud | last post by:
Here is some example code that produces an error: class Test(object): def greet(): print "Hello" t = Test() t.greet() TypeError: greet() takes no arguments (1 given)
2
4499
by: Nagu | last post by:
I am trying to save a dictionary of size 65000X50 to a local file and I get the memory error problem. How do I go about resolving this? Is there way to partition the pickle object and combine later if this is a problem due to limited resources (memory) on the machine (it is 32 bit machine Win XP, with 4GB RAM). Here is the detail...
0
1732
by: Nagu | last post by:
I am trying to save a dictionary of size 65000X50 to a local file and I get the memory error problem. How do I go about resolving this? Is there way to partition the pickle object and combine later if this is a problem due to limited resources (memory) on the machine (it is 32 bit machine Win XP, with 4GB RAM). Please advice. Thank you,
0
7845
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
8281
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
7868
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
8143
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
6515
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
5664
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...
0
5338
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2286
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
0
1107
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.