473,396 Members | 1,971 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,396 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 1280
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Jane Austine | last post by:
As you add more items, say text lines, in Text widget, it gets too slow and almost impractical to use on. Take idle for example. If the text gets bigger(e.g. print...
3
by: Phil Schmidt | last post by:
I'm trying to make a custom entry widget, as in the code that follows. There are two problems I'm trying to fix: 1) I would like the widget to behave as myEntry.Escape() does now, except that it...
6
by: William Gill | last post by:
I am trying to get & set the properties of a widget's parent widget. What I have works, but seems like a long way around the block. First I get the widget name using w.winfo_parent(), then i...
1
by: Shankar Iyer (siyer | last post by:
Hi, I am still new to Python and Tkinter, so I apologize in advance if I do not word my question optimally. I am trying to use a frame widget as the parent for other widgets. There is a class...
1
by: sven_c_t | last post by:
Hi! Probably a newbie question. I´ve been working a bit with the widget toolkit FLTK and I have been wondering why there is such a heavy use of the new operator, when it does not seem to be...
4
by: sullivanz.pku | last post by:
Hi all I am using the standard python GUI Tkinter as my program's main interface. Although I know wxPython has some widget to support rich text widget, but I do not have time to shift to wx----...
1
by: aeroumr | last post by:
In the following code, I have created a panel with a button and a textctrl object on it. I have also created a menubar that will create a new text file (i.e. textctrl object). My problem is that...
0
by: Phil Thompson | last post by:
On Sunday 04 May 2008, Lance Gamet wrote: I think QMainWindow.setCentralWidget() is what you are looking for. The eric4 IDE probably covers most things you'll ever need. Phil
0
by: David Boddie | last post by:
On Mon May 26 17:37:04 CEST 2008, Alex Gusarov wrote: Right. I vaguely remember someone showing something like this at EuroPython a couple of years ago. I believe that this approach is actually...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
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...
0
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,...

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.