3
我寫了全局快捷鍵示例隱藏並顯示我的窗口與鍵'F12',我用python-xlib和一些名爲'pyxhook'的腳本一切正常,除了當我想隱藏)和顯示()窗口幾次我的進程變成殭屍,但相同的代碼隱藏和顯示只是按鈕。python gtk gobject切換窗口的可見性
#!/usr/bin/python
# -*- coding: utf-8; -*-
from gi.repository import Gtk, GObject
from pyxhook import HookManager
GObject.threads_init()
class Win(Gtk.Window):
def __init__(self):
super(Win, self).__init__()
self.connect('destroy', Gtk.main_quit)
self.button = Gtk.Button()
self.add(self.button)
self.resize(200,150)
self.show_all()
def handle_global_keypress(self, event):
if event.Key == 'F12':
if self.get_visible():
self.hide()
else:
self.show()
### this part works fine with button
#if self.button.get_visible():
# self.button.hide()
#else:
# self.button.show()
def main():
app = Win()
hm = HookManager()
hm.HookKeyboard()
hm.KeyDown = app.handle_global_keypress
hm.start()
Gtk.main()
hm.cancel()
if __name__ == "__main__":
main()
編輯:我解決了我的問題,使用Keybinder庫而不是編碼純python keybinder。 http://kaizer.se/wiki/keybinder/