0

I used PythonCard to make my GUI and the only menu items I have currently are Save and Exit. Exit is fully functional and closes the program; but when I click on Save nothing happens. I can only assume the command is wrong. I have done some thorough searching and have found nothing. The command I used was "save". Obviously this is not correct. Can anyone tell me what command I need to use?

Resource File

1 Answers1

0

There's really not enough information here. You need to bind EVT_MENU to an event handler for the save menu item. Then in the event handler, you'll have to define what the "Save" behavior is. For example, does it save to a database, a file, or what? Once you have that figured out, you put it in your handler and do it or have the handler spin up a thread.

EDIT: If you want to save a file, see the wx.FileDialog and set the style flag to wx.SAVE. Something like this should work:

def onSaveFile(self, event):
    """
    Create and show the Save FileDialog
    """
    wildcard = "Text (*.txt)|*.txt|" \
            "All files (*.*)|*.*"
    dlg = wx.FileDialog(
        self, message="Save file as ...", 
        defaultDir=self.currentDirectory, 
        defaultFile="", wildcard=wildcard, style=wx.SAVE
        )
    if dlg.ShowModal() == wx.ID_OK:
        path = dlg.GetPath()
        print "You chose the following filename: %s" % path
    dlg.Destroy()

See also the wxPython demo, or this or the docs

Mike Driscoll
  • 32,629
  • 8
  • 45
  • 88
  • I want it to save to the desktop by default. Could you tell me how that is done? – user2256760 Apr 10 '13 at 15:31
  • Save what? Basically you'll want to open a file path with the "w" (write) flag and then write your data to it. See the Python docs: http://docs.python.org/2/tutorial/inputoutput.html#methods-of-file-objects – Mike Driscoll Apr 10 '13 at 16:08
  • Right, this is my GUI. It is a simple code editor. Basically it is a notepad GUI. I want my save feature to act like it normally would in notepad - open up the window where you select the location. I want the default in the name area to be *.txt That's about it really. – user2256760 Apr 12 '13 at 16:27
  • The following is my resource file. Does your code require a specific location? – user2256760 Apr 13 '13 at 08:52
  • Scratch that it's in the top. – user2256760 Apr 13 '13 at 08:58