Python 2.7: getting segmentation fault when customizing menus in GUI with Tkinter
I am getting segmentation fault every time I want to run this code:
from Tkinter import *
def gui():
root=Tk()
menubar=Menu(root)
filemenu=Menu(menubar,tearoff=0)
filemenu.add_command(label='New',command=gui)
filemenu.add_command(label='Close',command=root.quit)
menubar.add_cascade(label='File',menu=filemenu)
helpmenu=Menu(menubar,tearoff=1)
helpmenu.add_separator()
helpmenu.add_command(label="Help")#ajouter commande
helpmenu.add_command(label='About...')#ajouter commande
helpmenu.add_cascade(label='Help',menu=helpmenu)
root.mainloop()
gui()
Any suggestion? What should I do? Thank you in advance. FMF
+3
source to share
1 answer
Segfault is called:
helpmenu.add_cascade(label='Help',menu=helpmenu)
after a quick look at the documents, it makes sense why this will give you problems. Add cascade "adds a hierarchical menu item". You add helpmenu as a menu to helpmenu.
I believe what you mean here
menubar.add_cascade(label="Help", menu=helpmenu)
+5
source to share