Skip to content
Advertisement

How do I make menu options do different things in WxPython?

I have a problem with my menu in WxPython! In the file header I have ‘File’ and in that I have 2 options, ‘Save’ and ‘Close’…When I click save, I want it to print “Saved” and when I clock quit, the application should print “Closed” and close…But if I click even save it’s closing! So can you please help me. Here is a part of my code:

JavaScript

And the functions:

JavaScript

Advertisement

Answer

The first parameter of fileMenu.Append is important. It is used to tell one menu item from the other one, but you used the same value for both.

JavaScript

In my programs I prefer getting a free id from system, using wx.NewId(). If you have these “stock” menu entries, ID_SAVE and ID_EXIT make perfect sense, but if you make your own entries, you can do:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement