Hi everyone,
For a desktop application, I wanted to provide a way to have a default button, fired when I press enter.
The solution I found works perfectly, but has a strange (for me) effect: If I try to move the window, the program crash with the error :
AttributeError: 'myApp' object has no attribute 'to_window'
Here is a minimal exemple
file pbme_to_window.py
from kivy.app import App
from kivy.app import Builder
from kivy.core.window import Window
class myApp(App):
def __init__(self, **kwargs):
super(myApp, self).__init__(**kwargs)
self._keyboard = Window.request_keyboard(self._keyboard_closed, self)
self._keyboard.bind(on_key_down=self._on_keyboard_down)
def _keyboard_closed(self):
self._keyboard.unbind(on_key_down=self._on_keyboard_down)
self._keyboard = None
def build(self):
kv = Builder.load_file('pbme_to_window.kv')
return kv
def _on_keyboard_down(self, keyboard, keycode, text, modifiers):
if keycode[1] == 'enter':
saisie()
def saisie(self):
print('Le bouton a été pressé')
if __name__ == '__main__':
myApp().run()
file pbme_to_window.kv
BoxLayout:
orientation: "vertical"
BoxLayout:
size_hint: 1, .1
orientation: "horizontal"
Label:
size_hint : 3, 1
text: "Titre"
BoxLayout:
orientation: "horizontal"
BoxLayout:
orientation: "horizontal"
size_hint: 1, .2
BoxLayout:
orientation: "vertical"
size_hint: (0.2, 1)
Button:
size_hint_x: 0.25
pos_hint: {'center_x':0.5, 'center_y': 0.5}
text: "Bouton"
on_release: app.saisie()
If i delete the 2 lines keyboard from __init__ I can move the window without problem...
Frederic