Sir:
I am upgrading a python2 (wx version: 3.0.2.0) script to python3 (wx version: 4.0.7)
It looks like that the script works correct, but wxPyDeprecationWarning: pops out.
Script is:
wx.EVT_SET_FOCUS(#obj, self.onFocus)
#obj isa TextCtrl (or derived) object, self.onFocus is a handler.
Warning is:
Call to deprecated item call. Use :meth:EvtHandler.Bind
instead.
self.Bind(wx.EVT_SET_FOCUS, self.onFocus) and self.Bind(wx.EVT_SET_FOCUS, source=#obj) both are not working correct.
All other EVT_'s are successfully converted to self.Bind(wx.EVT_ , handler, id=**)
So far, I have been unable to find call method for wx.FocusEvent.
Can any expert please direct me to next step?
Thank you in advance.
regards
Does the following code demonstrate what you want?
import wx
class MyFrame(wx.Frame):
def __init__(self, *args, **kwds):
kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
self.SetSize((200, 200))
self.SetTitle("Focus Event Handler")
self.panel_1 = wx.Panel(self, wx.ID_ANY)
sizer_1 = wx.BoxSizer(wx.VERTICAL)
self.text_ctrl_1 = wx.TextCtrl(self.panel_1, wx.ID_ANY, "1st TextCtrl")
sizer_1.Add(self.text_ctrl_1, 0, 0, 0)
self.text_ctrl_2 = wx.TextCtrl(self.panel_1, wx.ID_ANY, "2nd TextCtrl")
sizer_1.Add(self.text_ctrl_2, 0, 0, 0)
self.panel_1.SetSizer(sizer_1)
self.Layout()
self.text_ctrl_1.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus)
self.text_ctrl_2.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus)
def OnSetFocus(self, event):
ctrl = event.GetEventObject()
print(ctrl.GetValue())
class MyApp(wx.App):
def OnInit(self):
self.frame = MyFrame(None, wx.ID_ANY, "")
self.SetTopWindow(self.frame)
self.frame.Show()
return True
if __name__ == "__main__":
app = MyApp(0)
app.MainLoop()
Thanks for your post.
I have not understood the logic behind, but “self.#obj.Bind(EVT_SET_FOCUS, self.hander)” looks working correct.
I was spending time with this page (self.Bind vs. self.button.Bind - wxPyWiki), but not completed yet (at all ?).