Created
October 7, 2023 05:42
-
-
Save yoya/30ed5c42641e13a8d7409955ae03fac7 to your computer and use it in GitHub Desktop.
wx.TextCtrl に EVT_KILK_FOCUS をセットするサンプル
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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