出于某种原因,它没有读取任何按下的键,我整天都在寻找示例和修复,但无济于事,我不知道为什么。尝试使用面板如下所示,但我用来了解 wxpython 的教程有问题,即使那里代码的复制粘贴也不起作用。那里的例子不使用面板,而只是一个 self.Bind(wx.EVT_KEY_UP,self.keyPressed)。任何人都可以帮助这个初学者吗?
import wx
import time
from threading import Thread
class frame(wx.Frame):
def __init__ (self):
style = (wx.CLIP_CHILDREN | wx.STAY_ON_TOP | wx.FRAME_NO_TASKBAR | wx.NO_BORDER |wx.FRAME_SHAPED)
wx.Frame.__init__(self,None, title='test', style = style, size = (300,150))
self.panel = wx.Panel(self,-1)
self.Bind(wx.EVT_KEY_DOWN, self.keyPressed, self.panel)
self.SetFocus()
self.SetTransparent(0)
self.Show(True)
def keyPressed(self,event=None):
print "somethine is pressed"
key = event.GetKeyCode()
if key == wx.WXK_ESCAPE or key == ord('Q'):
self.Close(force=True)
self.Show(False)
else:
event.Skip()
def duration(self, dur):
start = int(time.time())
self.closeTime = False
while not self.closeTime:
actDur = int(time.time()) -start
if actDur == dur:
self.Show(False)
self.closeTime = True
app = wx.App(False)
f = frame()
#timing = Thread(target=f.duration, args= (5,))
#timing.start()
app.MainLoop()