Is there an option to create keyboard shortcut Ex.- Ctrl+Q to exit the application / close the window of a desktop application written in Kivy and Python? I am on Windows OS.
Thank you in advance.
- Arnab
Is there an option to create keyboard shortcut Ex.- Ctrl+Q to exit the application / close the window of a desktop application written in Kivy and Python? I am on Windows OS.
Thank you in advance.
Kivy's Window.on_keyboard
(doc) event allows you to catch keyboard key pressing event.
Example app that exits if press ctrl+q
:
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.core.window import Window
class RootWidget(BoxLayout):
pass
class TestApp(App):
def build(self):
Window.bind(on_keyboard=self.on_keyboard) # bind our handler
return RootWidget()
def on_keyboard(self, window, key, scancode, codepoint, modifier):
if modifier == ['ctrl'] and codepoint == 'q':
self.stop()
if __name__ == '__main__':
TestApp().run()