2

I have a simple kivy app with 3 buttons. When my kivy app is not in focus, I have to click on it once, in order to press any button. How can I click any button with only one click without activating a kivy window?

#:kivy 1.10.0

cannot press any button, when a window is not in focus

eyllanesc
  • 235,170
  • 19
  • 170
  • 241

3 Answers3

2

I encountered this issue recently as well. Couldn't find a solution but I did implement a workaround that worked. What I did was bound kivy.core.window.Window to on_cursor_enter to trigger a callback that brings the kivy app to foreground, gaining focus, whenever the mouse enters back into the kivy app window:

Window.bind(on_cursor_enter=mouseEnter)

def mouseEnter(instance):
    Window.raise_window()
Jack Chen
  • 21
  • 1
1

I was inspired by Jack's answer. I have found that Window.raise_window causes the taskbar icon to start flashing (at least on Windows 10), so I would recommend using Window.show instead. This seems to work just the same, but does not make the taskbar icon flash.

Full code:

Window.bind(on_cursor_enter=lambda *__: Window.show())
Jakub Bláha
  • 1,491
  • 5
  • 22
  • 43
0

Just add the following at the top of your code:

import os
os.environ["SDL_MOUSE_FOCUS_CLICKTHROUGH"] = '1'

See discussion at: https://groups.google.com/g/kivy-users/c/b1wXKpjzjkg/m/5HF6WxSyAwAJ

Bill Bridge
  • 821
  • 1
  • 9
  • 30