Forum: Poser Python Scripting


Subject: running two scripts (with tkinter GUI) at the same time

tromnek opened this issue on Dec 04, 2004 ยท 10 posts


PoseWorks posted Mon, 06 December 2004 at 6:32 PM

When you have two Tk apps, you should use Toplevel for the newest window.

I like to build my window classes with an argument to take a root window. That way I can feed them an appropriate root window:

from Tkinter import *

class NewWin:
-----def init(self, root_win=None):
----------if root_win:
---------------self.root = root_win
----------else:
---------------self.root = Tk()
---------------self.root.protocol('WM_DELETE_WINDOW',self.destroy)
-----def mainloop(self):
----------self.root.mainloop()
-----def destroy(self):
----------self.root.destroy()

if name == 'main':
-----test_win = NewWin()

-----test_win.top = Toplevel()
-----test_win.son_of_test_win = NewWin(test_win.top)

-----test_win.mainloop()

#PoserPython hates it when you end on a tabbed line

You end up with a few more lines of code, but it may be worth it in a multi-window environment. (Remember, any extra windows should ultimately be slaved under the master window [master.slave], that way you can be absolutely sure that everything gets destroyed once the master window is destroyed.)

Message edited on: 12/06/2004 18:34