Skip to content

Instantly share code, notes, and snippets.

@yoya
Created October 7, 2023 05:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yoya/30ed5c42641e13a8d7409955ae03fac7 to your computer and use it in GitHub Desktop.
Save yoya/30ed5c42641e13a8d7409955ae03fac7 to your computer and use it in GitHub Desktop.
wx.TextCtrl に EVT_KILK_FOCUS をセットするサンプル
import wx
class Frame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, size=wx.Size(300, 200))
panel = wx.Panel(self, wx.ID_ANY)
self.text = "ABC..."
textCtrl = wx.TextCtrl(panel, wx.ID_ANY, self.text,
size=wx.Size(90, -1), style=wx.TE_PROCESS_ENTER)
for evt in [wx.EVT_KILL_FOCUS, wx.EVT_TEXT_ENTER]:
# self.Bind(evt, self.OnText, textCtrl) # こっちは NG
textCtrl.Bind(evt, self.OnText) # こっちは OK
def OnText(self, event):
t = event.GetEventObject().GetValue()
if self.text != t:
mesg ="{} => {}".format(self.text, t)
print(mesg)
self.text = t # MessageBox で再び KILL_FOCUS 動くのでここで代入
wx.MessageBox(mesg)
app = wx.App()
frame = Frame()
frame.Show()
app.MainLoop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment