Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tkinter menu delete item

How can I delete any menu items? For example I want to delete "Play".

self.menubar = Menu(self.root)
self.root.config(menu=self.menubar)


self.filemenu2 = Menu(self.menubar)
self.label2=self.menubar.add_cascade(label="Sound", menu=self.filemenu2)

self.menuPlay = self.filemenu2.add_command(label="Play", state=DISABLED, accelerator="Ctrl+P")
self.menuStop = self.filemenu2.add_command(label="Stop", state=DISABLED, accelerator="Ctrl+S")
like image 956
user3240368 Avatar asked Dec 15 '22 01:12

user3240368


1 Answers

Menu widgets have a delete method. You can give an index (zero-based), or you can give the label of the item to delete:

self.filemenu2.delete(0) # deletes first item in menu
self.filemenu2.delete("Stop") $ delete item with the label "Stop"
like image 173
Bryan Oakley Avatar answered Jan 04 '23 17:01

Bryan Oakley