473,738 Members | 3,658 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 1965
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
5981
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 application yet. I've trivially subclassed Tkinter.Canvas into ColorCanvas, added a bunch of ColorCanvases...
2
4736
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 the error code. I trap the error with a simple : (excuse the horrible indentation, this is from...
5
8258
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
1817
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 with the desired join key in the 'many-only' table."
18
3799
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. This is what I have, can anyone help me out with this?
2
2608
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
3033
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
4512
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 description of the error:
0
1782
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
8968
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8787
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9473
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9334
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9208
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6053
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4824
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2193
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.