PyGTK Hotkey
Linux tutorials and code.
1 post
Page 1 of 1
Today's tutorial is pretty simple, we're going to take a basic window (As created in this tutorial) and add a simple hotkey to it, and just to keep it super simple, we're going to have it so when users press the escape key; the window closes.
Lets startout with our basic window.
So here's the full code for this simple app.
Lets startout with our basic window.
Code: Select all
Now before we make the hotkey lets add the following keypress signal, below the window destory signal.
#!/usr/bin/env python
import gtk
class app:
def __init__(self):
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.set_position(gtk.WIN_POS_CENTER)
window.set_title("TestApp")
window.set_default_size(320, 200)
window.connect("destroy", gtk.main_quit)
window.show_all()
app()
gtk.main()
Code: Select all
Now lets make the hotkey with the following code.
window.connect("key-press-event", self.closeapp)
Code: Select all
See how easy that is? def closeapp(self, widget, event) :
if event.keyval == gtk.keysyms.Escape :
gtk.main_quit()
So here's the full code for this simple app.
Code: Select all
Enjoy!#!/usr/bin/env python
import gtk
class app:
def closeapp(self, widget, event) :
if event.keyval == gtk.keysyms.Escape :
gtk.main_quit()
def __init__(self):
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.set_position(gtk.WIN_POS_CENTER)
window.set_title("TestApp")
window.set_default_size(320, 200)
window.connect("destroy", gtk.main_quit)
window.connect("key-press-event", self.closeapp)
window.show_all()
app()
gtk.main()
1 post
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023