wxPython Error

Thread Solved

Join Date: Sep 2008
Posts: 369
Reputation: tomtetlaw is an unknown quantity at this point 
Solved Threads: 4
tomtetlaw's Avatar
tomtetlaw tomtetlaw is offline Offline
Posting Whiz

wxPython Error

 
0
  #1
Jun 30th, 2009
When I run this code:

  1. import wx
  2.  
  3. ID_FILE_QUIT = 101
  4.  
  5. class MainFrame(wx.Frame):
  6. def __init__(self, title):
  7. wx.Frame.__init__(self, None, wx.ID_ANY, title=title)
  8. self.menuBar = wx.MenuBar()
  9. self.fileMenu = wx.Menu()
  10. self.fileMenu.Append(1, '&Quit\tCtrl+Q')
  11. self.Bind(wx.EVT_MENU, self.Close(), id=ID_FILE_QUIT)
  12. self.menuBar.Append(self.fileMenu, '&File')
  13. self.SetMenuBar(self.menuBar)
  14. self.Show()
  15.  
  16. app = wx.App()
  17. frame = MainFrame('Ya Mum')
  18. 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.
...
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 899
Reputation: Paul Thompson has a spectacular aura about Paul Thompson has a spectacular aura about 
Solved Threads: 145
Sponsor
Paul Thompson's Avatar
Paul Thompson Paul Thompson is offline Offline
previously paulthom12345

Re: wxPython Error

 
0
  #2
Jun 30th, 2009
  1.  
  2. self.Bind(wx.EVT_MENU, self.Close(), id=ID_FILE_QUIT)
Theres ya problem!
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
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 1,521
Reputation: Lardmeister is an unknown quantity at this point 
Solved Threads: 22
Lardmeister's Avatar
Lardmeister Lardmeister is offline Offline
Posting Virtuoso

Re: wxPython Error

 
0
  #3
Jun 30th, 2009
If paulthom12345's suggestion does not fix your problem, try to bind this way:
  1. import wx
  2.  
  3. ID_FILE_QUIT = 101
  4.  
  5. class MainFrame(wx.Frame):
  6. def __init__(self, title):
  7. wx.Frame.__init__(self, None, wx.ID_ANY, title=title)
  8. self.menuBar = wx.MenuBar()
  9. self.fileMenu = wx.Menu()
  10. self.fileMenu.Append(ID_FILE_QUIT, '&Quit\tCtrl+Q')
  11. self.Bind(wx.EVT_MENU, self.quit, id=ID_FILE_QUIT)
  12. self.menuBar.Append(self.fileMenu, '&File')
  13. self.SetMenuBar(self.menuBar)
  14. self.Show()
  15.  
  16. def quit(self, event):
  17. self.Close(True)
  18.  
  19.  
  20. app = wx.App()
  21. frame = MainFrame('Ya Mum')
  22. app.MainLoop()
I upped my sanitary measures, up yours!
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 1,521
Reputation: Lardmeister is an unknown quantity at this point 
Solved Threads: 22
Lardmeister's Avatar
Lardmeister Lardmeister is offline Offline
Posting Virtuoso

Re: wxPython Error

 
0
  #4
Jul 1st, 2009
Forgot to mention this, but I also corrected line 10 to:

self.fileMenu.Append(ID_FILE_QUIT, '&Quit\tCtrl+Q')
I upped my sanitary measures, up yours!
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 369
Reputation: tomtetlaw is an unknown quantity at this point 
Solved Threads: 4
tomtetlaw's Avatar
tomtetlaw tomtetlaw is offline Offline
Posting Whiz

Re: wxPython Error

 
0
  #5
Jul 2nd, 2009
Thanks guys, it turns out that I had to only put the function name, not call the function.
...
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,003
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 928
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: wxPython Error

 
0
  #6
Jul 3rd, 2009
Originally Posted by tomtetlaw View Post
Thanks guys, it turns out that I had to only put the function name, not call the function.
Better test it, that won't work!
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 489
Reputation: shadwickman will become famous soon enough shadwickman will become famous soon enough 
Solved Threads: 76
shadwickman's Avatar
shadwickman shadwickman is offline Offline
Posting Pro in Training

Re: wxPython Error

 
0
  #7
Jul 3rd, 2009
Originally Posted by vegaseat View Post
Better test it, that won't work!
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.
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
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,357
Reputation: evstevemd has a spectacular aura about evstevemd has a spectacular aura about evstevemd has a spectacular aura about 
Solved Threads: 127
evstevemd's Avatar
evstevemd evstevemd is offline Offline
Nearly a Posting Virtuoso

Re: wxPython Error

 
0
  #8
Jul 3rd, 2009
Originally Posted by
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.
here is what I got:

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
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,357
Reputation: evstevemd has a spectacular aura about evstevemd has a spectacular aura about evstevemd has a spectacular aura about 
Solved Threads: 127
evstevemd's Avatar
evstevemd evstevemd is offline Offline
Nearly a Posting Virtuoso

Re: wxPython Error

 
0
  #9
Jul 3rd, 2009
I wonder how it runs on you!
What version of wxPython do you have?
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
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 489
Reputation: shadwickman will become famous soon enough shadwickman will become famous soon enough 
Solved Threads: 76
shadwickman's Avatar
shadwickman shadwickman is offline Offline
Posting Pro in Training

Re: wxPython Error

 
0
  #10
Jul 3rd, 2009
If you were to take the most updated code, you'd see that it works. This is what Lardmeister posted:
  1. import wx
  2.  
  3. ID_FILE_QUIT = 101
  4.  
  5. class MainFrame(wx.Frame):
  6. def __init__(self, title):
  7. wx.Frame.__init__(self, None, wx.ID_ANY, title=title)
  8. self.menuBar = wx.MenuBar()
  9. self.fileMenu = wx.Menu()
  10. self.fileMenu.Append(ID_FILE_QUIT, '&Quit\tCtrl+Q')
  11. self.Bind(wx.EVT_MENU, self.quit, id=ID_FILE_QUIT)
  12. self.menuBar.Append(self.fileMenu, '&File')
  13. self.SetMenuBar(self.menuBar)
  14. self.Show()
  15.  
  16. def quit(self, event):
  17. self.Close(True)
  18.  
  19.  
  20. app = wx.App()
  21. frame = MainFrame('Ya Mum')
  22. app.MainLoop()
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().
"Two good old boys in a fire-apple red convertible. Stoned. Ripped. Twisted. Good people."
- Hunter S. Thompson

my photography
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC