| | |
wxPython Error
Thread Solved |
When I run this code:
I get some error about expecting a callable object for self.Bind()?
Can someone tell me why this is happening?
python Syntax (Toggle Plain Text)
import wx ID_FILE_QUIT = 101 class MainFrame(wx.Frame): def __init__(self, title): wx.Frame.__init__(self, None, wx.ID_ANY, title=title) self.menuBar = wx.MenuBar() self.fileMenu = wx.Menu() self.fileMenu.Append(1, '&Quit\tCtrl+Q') self.Bind(wx.EVT_MENU, self.Close(), id=ID_FILE_QUIT) self.menuBar.Append(self.fileMenu, '&File') self.SetMenuBar(self.menuBar) self.Show() app = wx.App() frame = MainFrame('Ya Mum') app.MainLoop()
I get some error about expecting a callable object for self.Bind()?
Can someone tell me why this is happening?
Last edited by tomtetlaw; Jun 30th, 2009 at 4:17 am.
...
python Syntax (Toggle Plain Text)
self.Bind(wx.EVT_MENU, self.Close(), id=ID_FILE_QUIT)
You dont need to put the brackets after self.Close, the brackets are only used if you actually want to call the function, so take out those brackets and try again. That hopefully should fix your dilemma.
Make it idiot proof and someone will make a better idiot.
Check out my Site | and join us on IRC | Python Specific IRC
Check out my Site | and join us on IRC | Python Specific IRC
If paulthom12345's suggestion does not fix your problem, try to bind this way:
python Syntax (Toggle Plain Text)
import wx ID_FILE_QUIT = 101 class MainFrame(wx.Frame): def __init__(self, title): wx.Frame.__init__(self, None, wx.ID_ANY, title=title) self.menuBar = wx.MenuBar() self.fileMenu = wx.Menu() self.fileMenu.Append(ID_FILE_QUIT, '&Quit\tCtrl+Q') self.Bind(wx.EVT_MENU, self.quit, id=ID_FILE_QUIT) self.menuBar.Append(self.fileMenu, '&File') self.SetMenuBar(self.menuBar) self.Show() def quit(self, event): self.Close(True) app = wx.App() frame = MainFrame('Ya Mum') app.MainLoop()
I upped my sanitary measures, up yours!
Last edited by shadwickman; Jul 3rd, 2009 at 3:53 pm.
"Two good old boys in a fire-apple red convertible. Stoned. Ripped. Twisted. Good people."
- Hunter S. Thompson
my photography
- Hunter S. Thompson
my photography
•
•
•
•
Originally Posted by
907747
907747
Why not? It worked for me when I tested his code... and there's nothing wrong with his binding as I added another menu item with a separate function and ID and that still worked without conflict.
File "c:\Users\Elijah Ministries\Desktop\daniweb.py", line 17, in <module>
frame = MainFrame('Ya Mum')
File "c:\Users\Elijah Ministries\Desktop\daniweb.py", line 11, in __init__
self.Bind(wx.EVT_MENU, self.Close(), id=ID_FILE_QUIT)
File "C:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 3911, in Bind
event.Bind(self, id, id2, handler)
File "C:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 3985, in Bind
target.Connect(id1, id2, et, function)
File "C:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 3868, in Connect
return _core_.EvtHandler_Connect(*args, **kwargs)
Atheist: God is man made imagination, he doesn't exist!
Theist: It's okay, can you imagine anything else that doesn't exist?
Junior MD --- Python, C++ and PHP
Theist: It's okay, can you imagine anything else that doesn't exist?
Junior MD --- Python, C++ and PHP
If you were to take the most updated code, you'd see that it works. This is what Lardmeister posted:
Which tom tetlaw acknowledged as he said "all I need to do is put the function name, not call the function". This is what we're doing by binding the function self.quit, rather than self.quit().
python Syntax (Toggle Plain Text)
import wx ID_FILE_QUIT = 101 class MainFrame(wx.Frame): def __init__(self, title): wx.Frame.__init__(self, None, wx.ID_ANY, title=title) self.menuBar = wx.MenuBar() self.fileMenu = wx.Menu() self.fileMenu.Append(ID_FILE_QUIT, '&Quit\tCtrl+Q') self.Bind(wx.EVT_MENU, self.quit, id=ID_FILE_QUIT) self.menuBar.Append(self.fileMenu, '&File') self.SetMenuBar(self.menuBar) self.Show() def quit(self, event): self.Close(True) app = wx.App() frame = MainFrame('Ya Mum') app.MainLoop()
"Two good old boys in a fire-apple red convertible. Stoned. Ripped. Twisted. Good people."
- Hunter S. Thompson
my photography
- Hunter S. Thompson
my photography
![]() |
Similar Threads
- Compiling SPE IDE Using PY2EXE (Python)
- PyScripter and WxPython debug session (Python)
- How to use wxPython demo (Python)
- wxPython Error while running. (Python)
- wxpython gdk error on fedora 5 (fc5) (Python)
- wxpython labels (Python)
- wxPython slider help (Python)
Other Threads in the Python Forum
- Previous Thread: (text) summary screen during large data conversion
- Next Thread: Adress book
| Thread Tools | Search this Thread |
accessdenied advanced apache application argv array beginner book change command converter countpasswordentry csv curved dan08 def dictionary dynamic edit enter event examples file float format function google gui homework import inches input jaunty java keyboard lapse library line lines linux list lists loop microphone mouse movingimageswithpygame mysqlquery newb number numbers numeric obexftp output parameters parsing path phonebook plugin port prime programming projects py2exe pygame pygtk pyopengl python random recursion redirect remote return reverse scrolledtext session simple skinning software sprite statictext string strings syntax terminal text threading time tlapse trick tuple tutorial ubuntu unicode unit urllib urllib2 variable voip wordgame wxpython






