| | |
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 3: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 just 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 2:53 pm.
"Two good old boys in a fire-apple red convertible. Stoned. Ripped. Twisted. Good people."
- Hunter S. Thompson
- Hunter S. Thompson
•
•
•
•
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?
"Try to be expert in everything and you become expert in nothing" - Me
---------------------------------
Windows Vista Home Premium SP2| MINGW 4.4.0|PHP 5.3.1|Python 2.6.4|JDK 1.6
Theist: It's okay, can you imagine anything else that doesn't exist?
"Try to be expert in everything and you become expert in nothing" - Me
---------------------------------
Windows Vista Home Premium SP2| MINGW 4.4.0|PHP 5.3.1|Python 2.6.4|JDK 1.6
I wonder how it runs on you!
What version of wxPython do you have?
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?
"Try to be expert in everything and you become expert in nothing" - Me
---------------------------------
Windows Vista Home Premium SP2| MINGW 4.4.0|PHP 5.3.1|Python 2.6.4|JDK 1.6
Theist: It's okay, can you imagine anything else that doesn't exist?
"Try to be expert in everything and you become expert in nothing" - Me
---------------------------------
Windows Vista Home Premium SP2| MINGW 4.4.0|PHP 5.3.1|Python 2.6.4|JDK 1.6
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
- Hunter S. Thompson
![]() |
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
Views: 611 | Replies: 12
| Thread Tools | Search this Thread |
Tag cloud for Python
application array bash beginner c++ c/c++ change character class client code command convert count create csv ctypes database dictionary django dll error event examples excel exe extensions fdlib file float format framework ftp function graphics gui homework image images import input library line linux list lists logging loop loops microcontroller mouse mysql mysqldb number numbers output parse parsing path port prime processing program programming py2exe pygame pygtk pyqt python random raw_input recursion recursive redirect remote scrolledtext server socket split ssh stdout string strings syntax table terminal text thread threading tkinter transparency tuple tutorial ubuntu unicode variable variables web windows wxpython






