[Tkinter-discuss] python tcl mixed programming
Jeff Epler
jepler at unpythonic.net
Mon May 21 15:33:46 CEST 2007
This is the way I found to do it:
http://cvs.linuxcnc.org/cgi-bin/cvsweb.cgi/emc2/lib/python/nf.py.in?rev=1.1
You're interested in the class 'Widgets' and the function 'makewidget'
which does all the work.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
class Widgets:
def __init__(self, master, *widgets):
for (name, klass, path) in widgets:
setattr(self, name, makewidget(master, klass, path))
def makewidget(master, klass, path):
path = str(path)
self = newinstance(klass)
if path[0] == '.':
if master._w == '.': self._name = path[1:]
else: self._name = path[len(master._w)+1:]
self._w = path
else:
self._name = path
if master._w == '.': self._w = '.' + path
else: self._w = master._w + '.' + path
self.children = {}
master.children[self._name] = self
self.master = master
self.tk = master.tk
return self
Here's a use of the Widgets class:
widgets = nf.Widgets(root_window,
("help_window", Toplevel, ".keys"),
("about_window", Toplevel, ".about"),
("text", Text, pane_bottom + ".t.text"),
("preview_frame", Frame, pane_top + ".preview"),
...)
after this, it is possible to refer to widgets.help_window, widgets.text, etc.
Jeff
More information about the Tkinter-discuss
mailing list