코드 만 (만 텍스트 상자 창에 있습니다) 간단한 UI를 작성하고, 기능 OnKeyDown
에 이벤트 wx.EVT_KEY_DOWN
을 결합하는 데 사용됩니다,하지만 난 Esc
키를 누르면, 창이 나타납니다 Esc
, Test
, 다음 다른 Esc
, Test
, 마침내 그것은 네 메시지 상자 후에 종료됩니다, 왜? 난 단지 두 개의 메시지 상자 int wx.WXK_ESCAPE
바인딩을 정의합니다.wxpython : 바인딩 기능을 두 번 입력하는 이유는 무엇입니까?
# -*- coding: utf-8 -*-
import wx
class Command(wx.Frame):
def __init__(self, parent, title):
super(Command, self).__init__(parent, title=title,
size=(600, 500))
self.InitUI()
self.Centre()
self.Show()
def InitUI(self):
pnl = wx.Panel(self)
self.Bind(wx.EVT_CHAR_HOOK, self.OnKeyDown)
hbox = wx.BoxSizer(wx.HORIZONTAL)
self.__tc_command = wx.TextCtrl(pnl, style=wx.TE_MULTILINE)
self.Bind(wx.EVT_CHAR_HOOK, self.OnKeyDown)
hbox.Add(self.__tc_command, proportion=1, flag=wx.ALL|wx.EXPAND, border=15)
pnl.SetSizer(hbox)
def OnKeyDown(self, evt):
"""Enter to send data, Esc to exit."""
key = evt.GetKeyCode()
if key == wx.WXK_ESCAPE:
##################Only two MessageBox, but pop up four##################
wx.MessageBox("Esc")
wx.MessageBox("Test")
##################Only two MessageBox, but pop up four##################
self.Close()
if key == wx.WXK_RETURN:
wx.MessageBox("Enter")
evt.Skip()
if __name__ == '__main__':
app = wx.App(redirect=False)
Command(None, title='Command')
app.MainLoop()
왜 'EVT_CHAR_HOOK'을 (를)'OnKeyDown '에 두 번 바인딩합니까? 'self.InitUI'에는 두 개의 동일한 바인딩이 있습니다. –