Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
281 views
in Technique[技术] by (71.8m points)

Kivy Window doesn't recive first touch when unfocused

Each time I tap my mouse anywhere outside kivy window and get back I have to tap the window twice to recive on_touch_down event. Is it possible to recive that event when I tap for the first time? The only event I recive is Window focus. My idea is to catch, if possible, touch from window argument and call on_touch_down. OFC I'm open to any solution to that problem.

from kivy.config import Config

Config.set('graphics', 'multisamples', '0')
Config.set('graphics', 'width', '400')
Config.set('graphics', 'height', '400')

Config.write()

from kivy.app import App
from kivy.lang.builder import Builder
from kivy.uix.boxlayout import BoxLayout
from kivy.core.window import Window


kv = '''

MyWindow:

'''

class MyWindow(BoxLayout):

    def __init__(self, *args, **kwargs):
        super().__init__(**kwargs)
        Window.bind(focus=self.window_focus)

    def window_focus(self, window, focus):
        print('WINDOW FOCUS', focus)
        if focus:
            # is it possible to get touch from window and call on_touch_down?
            pass
            

    def on_touch_down(self, touch):
        print('TOUCH DOWN')
        return super().on_touch_down(touch)

class MyApp(App):
    def build(self):

        return Builder.load_string(kv)

if __name__ == '__main__':
    MyApp().run()
question from:https://stackoverflow.com/questions/65844950/kivy-window-doesnt-recive-first-touch-when-unfocused

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...