So in normal python scripts you can do something like this:
def func():
i = 1
return i
i = func()
Generally speaking, another python program would be able to import the file containing this and just say i = func() in their program and they would get the value of i.
Now I want to do something similar but instead I need to do it when a user presses a button or activates an event handler from the GUI. Something like:
import wx
class MyForm(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, "Pressing dem keyz")
# Add a panel so it looks the correct on all platforms
panel = wx.Panel(self, wx.ID_ANY)
self.btn = wx.ToggleButton(panel, label="TOGGLE")
self.btn2 = wx.ToggleButton(panel, label="TOGGLE 2", pos = (85,0))
self.btn.Bind(wx.EVT_CHAR_HOOK, self.onKeyPress)
self.btn2.Bind(wx.EVT_CHAR_HOOK, self.onKeyPress)
def onKeyPress(self, event):
space = False
keycode = event.GetKeyCode()
print keycode
if keycode == ord(' '):
print "SPACEBAR!"
space = True
self.btn.SetValue(space)
if space == True:
print "Lemme return i please"
i = 1
print i
return i #ALSO PART OF WHAT I WANT TO DO
elif keycode == wx.WXK_RETURN:
self.btn
elif keycode == wx.WXK_LEFT:
self.btn2
print 'YOU MOVED LEFT'
elif keycode == wx.WXK_RIGHT:
self.btn
print 'YOU MOVED RIGHT'
elif keycode == wx.WXK_UP:
print 'YOU MOVED UP'
elif keycode == wx.WXK_DOWN:
print 'YOU MOVED DOWN'
elif keycode == wx.WXK_ESCAPE:
self.Destroy()
#NOW HERE'S THE PART THAT I WANT TO IMPLEMENT
return keycode
#I do not need the keycode necessarily but I want to do something similar to this along with the |return i| above
# Run the program
if __name__ == "__main__":
app = wx.App(False)
frame = MyForm()
frame.Show()
app.MainLoop()
I have looked at these Call functions from within a wxPython event handler , Return value from wxpython main frame but they don't really address what I want to do here