I'm designing a desktop application using tkinter for the GUI. The application generates some nested data structures that I want to render graphically as trees. For that, I'm using the ete3 package. However, when I render the trees into an image file, the menus in the tkinter root window get messed up. The tree is rendered correctly into the image.
Here is a simplified version of the code, which has the same problem:
from tkinter import *
from tkinter import ttk, filedialog
from ete3 import Tree
root = Tk()
root.geometry("300x300")
menubar = Menu(root)
root['menu'] = menubar
file = Menu(menubar, tearoff=0)
menubar.add_cascade(menu=file, label='File')
file.add_command(label="Open")
def plot():
direction = filedialog.asksaveasfilename(defaultextension=".jpg", filetypes=(("jpg file", "*.jpg"),))
tree = Tree("((a,b),c);")
tree.render(direction)
ttk.Button(root, text="Plot tree to file", command=plot).grid()
root.mainloop()
The application, before rendering the tree, looks like this: image1
And after rendering the tree: image2
Also, if I delete the tree.render(direction)
line, the problem doesn't occur.
Any ideas what might be causing this?