wxPython的按键绑定不会在Linux上运行 [英] wxPython Key Bindings don't work on Linux

查看:396
本文介绍了wxPython的按键绑定不会在Linux上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的程序在Windows而不是Linux中对我的作品。有些时候我preSS,我绑定键显示没有打印报表。但是,Tab键可以在两个按键和拨动他们的进入和空格键之间切换。没有其他键的工作。

 进口WX类MyForm的(wx.Frame):
    高清__init __(个体经营):
            wx.Frame .__的init __(个体经营,无,wx.ID_ANY,pressing DEM keyz)            #添加一个面板,所以它看起来在所有平台上正确
            面板= wx.Panel(个体经营,wx.ID_ANY)
            self.btn = wx.ToggleButton(面板,标签=切换)
            self.btn2 = wx.ToggleButton(面板,标签=切换2,POS =(85,0))            self.btn.Bind(wx.EVT_CHAR_HOOK,self.onKey preSS)
            self.btn2.Bind(wx.EVT_CHAR_HOOK,self.onKey preSS)    DEF安其preSS(个体经营,事件):
            空间=假
            关键code = event.GetKey code()
            打印键code
            如果key code == wx.WXK_SPACE:
                    打印空格键!
                    空间= TRUE
            self.btn.SetValue(空间)
            如果空间==真:
                    打印做什么
            ELIF键code == wx.WXK_RETURN:
                    self.Hello()
            ELIF键code == wx.WXK_LEFT:
                    self.btn2
                    打印'你感动LEFT
            ELIF键code == wx.WXK_RIGHT:
                    self.btn
                    打印'你感动权
            ELIF键code == wx.WXK_UP:
                    打印你上移
            ELIF键code == wx.WXK_DOWN:
                    打印你下移
            ELIF键code == wx.WXK_ESCAPE:
                    self.Destroy()
    高清你好(个体经营):
            打印你好
            返回
 #运行程序
如果__name__ ==__main__:
        应用= wx.App(假)
        帧= MyForm的()
        frame.Show()
        app.MainLoop()


解决方案

或者的确,EVT_KEY_UP结果
它摆脱按住给多个按键事件的一个关键的问题。

The following program works for me in Windows but not in Linux. There are no print statements displayed when I press the keys that I binded. However, the tab key can switch between the two buttons and the enter and space key toggle them. No other keys work.

import wx

class MyForm(wx.Frame):
    def __init__(self):
            wx.Frame.__init__(self, None, wx.ID_ANY, "Pressing dem keyz")

            # Add a panel so it looks the correct on all platforms
            panel = wx.Panel(self, wx.ID_ANY)
            self.btn = wx.ToggleButton(panel, label="TOGGLE")
            self.btn2 = wx.ToggleButton(panel, label="TOGGLE 2", pos = (85,0))

            self.btn.Bind(wx.EVT_CHAR_HOOK, self.onKeyPress)
            self.btn2.Bind(wx.EVT_CHAR_HOOK, self.onKeyPress)

    def onKeyPress(self, event):
            space = False
            keycode = event.GetKeyCode()
            print keycode
            if keycode == wx.WXK_SPACE: 
                    print "SPACEBAR!"
                    space = True
            self.btn.SetValue(space)
            if space == True:
                    print "Do something"
            elif keycode == wx.WXK_RETURN:
                    self.Hello()
            elif keycode == wx.WXK_LEFT:
                    self.btn2
                    print 'YOU MOVED LEFT'
            elif keycode == wx.WXK_RIGHT:
                    self.btn
                    print 'YOU MOVED RIGHT'
            elif keycode == wx.WXK_UP:
                    print 'YOU MOVED UP'
            elif keycode == wx.WXK_DOWN:
                    print 'YOU MOVED DOWN'
            elif keycode == wx.WXK_ESCAPE:
                    self.Destroy()
    def Hello(self):
            print "Hello"
            return
 # Run the program
if __name__ == "__main__":
        app = wx.App(False)
        frame = MyForm()
        frame.Show()
        app.MainLoop()

解决方案

Or indeed, EVT_KEY_UP
which gets rid of the problem of a key held down giving multiple key down events.

这篇关于wxPython的按键绑定不会在Linux上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆