3

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

Malik Fassi
  • 488
  • 1
  • 10
  • 25

1 Answers1

5

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)
Nolen Royalty
  • 18,415
  • 4
  • 40
  • 50