Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python 2.7: Getting Segmentation fault when setting Menu in GUI programming with Tkinter

I'm getting a segmentation fault everytime 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. MFF

like image 706
Malik Fassi Avatar asked Aug 04 '26 06:08

Malik Fassi


1 Answers

The segfault is caused by:

helpmenu.add_cascade(label='Help',menu=helpmenu)

after a quick look at the docs, it makes perfect sense why that would give you problems. Add cascade "adds a hierarchical menu item". You are adding helpmenu as a menu within helpmenu.

I believe that what you mean here is

menubar.add_cascade(label="Help", menu=helpmenu)
like image 104
Nolen Royalty Avatar answered Aug 05 '26 23:08

Nolen Royalty



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!