471,356 Members | 1,642 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Wrap Tk widget using a class

I'm trying to wrap a subset of a Tcl/Tk widget set called tclmacbag (see
http://tclmacbag.autons.net/) for use in my Tkinter application, using a
"macnotebook" class. I'm having some difficulty getting things
configured correctly.

Here is my class code:

from Tkinter import *

class Macnotebook:

def __init__(self, master):

self.master = master
self.master.call('package', 'require', 'tclmacbag')
def notebook(self):

self.master.call('::tclmacbag::pnb', self)
def add(self, child):
self.master.call('::tclmacbag::pnb', 'add', child)

Here is an example of how I'm calling this in my code:

from Macnotebook import Macnotebook

self.prefbook = Macnotebook.notebook(self.prefframe)
self.prefbook.pack(fill=BOTH, expand=YES, side=TOP)

This returns the following error in my console:

Traceback (most recent call last):

self.prefbook = Macnotebook.notebook(self.prefframe)
TypeError: unbound method notebook() must be called with Macnotebook
instance as first argument (got Frame instance instead)

Can anyone suggest how I might better structure the class so that this
works? I'm a bit of a newbie with OO, so any pointers are appreciated.

--
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
Jan 10 '08 #1
1 1225
Kevin Walzer wrote:

Here is an example of how I'm calling this in my code:

from Macnotebook import Macnotebook

self.prefbook = Macnotebook.notebook(self.prefframe)
self.prefbook.pack(fill=BOTH, expand=YES, side=TOP)
you're attempting to call the method in a class object. I suspect that
you have to create an instance of that class first:

self.prefbook = Macnotebook(self.prefframe)
self.prefbook.notebook() # create it
self.prefbook.pack(...)

# call self.prefbook.add() to add pages to the notebook

(it's probably a good idea to move the notebook creation code into the
__init__ method; two-stage construction isn't very pythonic...)

</F>

Jan 10 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Jane Austine | last post: by
3 posts views Thread by Phil Schmidt | last post: by
6 posts views Thread by William Gill | last post: by
1 post views Thread by Shankar Iyer (siyer | last post: by
1 post views Thread by sven_c_t | last post: by
4 posts views Thread by sullivanz.pku | last post: by
reply views Thread by XIAOLAOHU | last post: by

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.