The callback mechanism provides a way for Tkinter menus to be updated each time through VMD's event loop. The following code shows how to override the Tk mainloop() method to let Tkinter menus peacefully coexist with VMD's event loop:
import VMDCallback import Tkinter def cb(foo, bar): foo.update() class VMDMenu(Tkinter.Tk): def mainloop(self): VMDCallback.add_callback('display_update', cb, self) self.bind("<Destroy>", self.unregister) def unregister(self, event=None): VMDCallback.del_callback('display_update', cb, self) def __del__(self): # unregister from display_update try: self.unregister() except: pass
VMDMenu instances can be used much like Tk instances. Here is an example, taken from John Grayson's "Python and Tkinter Programming", with the only difference being Tk replaced by VMDMenu:
from Tkinter import * import VMDMenu class App: def __init__(self, master): Button(master, text='Left').pack(side=LEFT) Button(master, text='Center').pack(side=LEFT) Button(master, text='Right').pack(side=LEFT) root = VMDMenu.VMDMenu() root.option_add('*font', ('verdana', 12, 'bold')) root.title("Pack - Example 1") display = App(root) root.mainloop()
Other strategies may also be of use, depending on your application.