How do I fix Kivy buttons being pressed outside of their borders?

Viewed 309

I have a program that creates a GridLayout() with buttons in it. For some reason they, are being pressed when clicking on a different button, or even when the window isn't even in focus. I would expect it to only trigger when I click on the button itself. I've tried searching both Google and StackOverflow, but I didn't find anything relevant to my issue.

Weirdly, the exact behavior varies somewhat. Sometimes, clicking a button in a specific area also triggers the one next to it. Other times, one button(chosen seemingly at random and staying constant until I stop the program) is triggered when I click anywhere within the window, in addition to the button that I actually pressed. Clicking outside of the window always triggers the button closest only.

My MRE is:

import kivy
kivy.require('2.0.0')

from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.button import Button

class MyApp(App):

    def build(self):
        layout = GridLayout(cols=2)
        layout.add_widget(Button(text = "Button 1"))
        layout.add_widget(Button(text = "Button 2"))
        layout.add_widget(Button(text = "Button 3"))
        layout.add_widget(Button(text = "Button 4"))
        return layout
    
if __name__ == '__main__':
    MyApp().run()

My shell output is:

[INFO   ] [Logger      ] Record log in /home/pi/.kivy/logs/kivy_21-01-10_29.txt
[INFO   ] [Kivy        ] v2.0.0
[INFO   ] [Kivy        ] Installed at "/home/pi/Programming/kivy_venv/lib/python3.7/site-packages/kivy/__init__.py"
[INFO   ] [Python      ] v3.7.3 (default, Jul 25 2020, 13:03:44) 
[GCC 8.3.0]
[INFO   ] [Python      ] Interpreter at "/home/pi/Programming/kivy_venv/bin/python"
[INFO   ] [Factory     ] 186 symbols loaded
[INFO   ] [Image       ] Providers: img_tex, img_dds, img_sdl2, img_pil (img_ffpyplayer ignored)
[INFO   ] [Text        ] Provider: sdl2(['text_pango'] ignored)
[INFO   ] [Window      ] Provider: sdl2
[INFO   ] [GL          ] Using the "OpenGL" graphics system
[INFO   ] [GL          ] Backend used <sdl2>
[INFO   ] [GL          ] OpenGL version <b'2.1 Mesa 19.3.2'>
[INFO   ] [GL          ] OpenGL vendor <b'Broadcom'>
[INFO   ] [GL          ] OpenGL renderer <b'V3D 4.2'>
[INFO   ] [GL          ] OpenGL parsed version: 2, 1
[INFO   ] [GL          ] Shading version <b'1.20'>
[INFO   ] [GL          ] Texture max size <4096>
[INFO   ] [GL          ] Texture max units <16>
[INFO   ] [Window      ] auto add sdl2 input provider
[INFO   ] [Window      ] virtual keyboard not allowed, single mode, not docked
[INFO   ] [ProbeSysfs  ] device match: /dev/input/event5
[INFO   ] [HIDInput    ] Read event from </dev/input/event5>
[INFO   ] [ProbeSysfs  ] device match: /dev/input/event1
[INFO   ] [HIDInput    ] Read event from </dev/input/event1>
[INFO   ] [ProbeSysfs  ] device match: /dev/input/event6
[INFO   ] [HIDInput    ] Read event from </dev/input/event6>
[INFO   ] [ProbeSysfs  ] device match: /dev/input/event4
[INFO   ] [HIDInput    ] Read event from </dev/input/event4>
[INFO   ] [ProbeSysfs  ] device match: /dev/input/event0
[INFO   ] [HIDInput    ] Read event from </dev/input/event0>
[INFO   ] [ProbeSysfs  ] device match: /dev/input/event7
[INFO   ] [HIDInput    ] Read event from </dev/input/event7>
[INFO   ] [Base        ] Start application main loop
[INFO   ] [HIDMotionEvent] using <USBPS2 Mouse��>
[INFO   ] [HIDMotionEvent] using <Logitech G305��>
[INFO   ] [HIDMotionEvent] using <USBPS2��>
[INFO   ] [HIDMotionEvent] using <USBPS2 Consumer Control��>
[INFO   ] [HIDMotionEvent] using <Logitech Wireless Mouse��>
[INFO   ] [GL          ] NPOT texture support is available
[INFO   ] [HIDMotionEvent] using <USBPS2 System Control��>

Window with nothing pressed(I don't have sufficient reputation to post images, so it's a link instead):

Window generated by program

In case it's relevant, I'm running an 8gb pi 4 with 32 bit Raspberry Pi OS.

0 Answers
Related