ase-gui can't be nested in a tkinter program
I am unsure of the best way to fix this problem, but ase-gui can't be used from within a tkinter program, including ase-gui itself. While this might sound strange at first, this problem has come up while attempting to use ase-gui to visualize and manipulate vibrational modes from within the gui of another tkinter program. For some reason the program will never continue past the atoms.edit() call, even if the ase-gui window is entirely closed.
I would like a proper way of doing this fixed at some point, but I don't know enough of the gritty details of tkinter to fix this. I think it is due to ase-gui starting its own mainloop for tkinter, even if one already exists.
Here is an example of how I managed to work around this, although I am not quite sure how I came to this workaround anymore. If a minimum failing example is needed, I can try to make one from scratch, but this program is far too long and not available right now.
def window_open():
try:
gui.window.win.state() # This will error if window closed
return True
except:
return False
def mode_show(a):
global gui, vals, curItem
if gui is not None:
return
curItem = tree.focus()
if curItem == "":
return
try:
vals = tree.item(curItem)["values"]
movie = get_mode_movie(atoms, modes[vals[0]])
from ase.gui.images import Images
from ase.gui.gui import GUI
import time
images = Images(movie)
gui = GUI(images)
gui.set_frame(len(gui.images) - 1, focus=True)
tk.after(100, gui_closed)
except:
print("Skipping showing mode, mode unavailable or GUI failed to load")
advanced_show(a)
def gui_closed():
global gui, vals, curItem
if window_open():
tk.after(1000, gui_closed)
return
# logic for handling the changes goes here