Tk communications between frames?
Michael P. Reilly
arcege at shore.net
Fri May 7 09:42:06 EDT 1999
David Miller <dmillerNO at MAPSmote.rsn.com> wrote:
: The application I'm developing in python/Tkinter needs to have
: a parent frame start some number of child browser frames. When the
: user double clicks on a file listed in a child listbox I want to
: insert the selection in a different listbox on the parent.
: Specifically, the parent is a master scheduling window. The child
: browsers drill down N directories deep, and there may be and number
: of child browsers. This is to let someone program video for playback
: at a TV station - pick a video from this category (sports tip, child1)
: a video from another category (athlete profile, child 2), then an ad
: from child 3.
: Is this easily doable? Doable without the security problems of send()?
Are the child frames seperate processes? Just toplevel windows within
the same process? If so, then there is no need to communicate over a
socket. Below assumes that the child frames are not seperate
processes.
I'm not sure how you would want to proceed, but my best suggestion
would be to take a more object oriented approach and less of a GUI
approach.
class Scheduler:
# no locking in this schedule, very simple
def __init__(self, master_frame):
self.queue = []
self.frame = Frame(master_frame)
self.create_widgets()
self.child_browser = Browser(self, self.frame)
self.frame.after_idle(self.do_work)
def add_workitem(self, item):
self.queue.append(item)
def do_work(self):
self.process_queue()
class Browser(Toplevel):
def __init__(self, scheduler, master):
Toplevel.__init__(self, master, bd=2)
self.scheduler = scheduler
self.listbox = Listbox(self, setgrid=1, relief=SUNKEN)
scroll = Scrollbar(self, command=self.listbox.yview, relief=SUNKEN)
self.listbox['yscrollcommand'] = scroll.set
self.bind('<Double-Button-1>', self.select)
scroll.pack(side=RIGHT, fill=Y, expand=YES)
self.listbox.pack(side=LEFT, fill=BOTH, expand=YES)
def select(self, event):
items = self.listbox.curselection()
# some versions of Tkinter do not convert to Python integers
try: items = map(string.atoi, items)
except ValueError: pass
itempos = items[0]
self.scheduler.add_workitem(self.listbox.get(itempos))
This lets you use the parent as a workhouse instead of as just a
widget, which may be more appropriate.
-Arcege
More information about the Python-list
mailing list