python - 如何修复在其边界之外按下的 Kivy 按钮?
问题描述
我有一个程序可以在其中创建一个GridLayout()
带有按钮的程序。出于某种原因,它们在单击其他按钮时被按下,甚至在窗口甚至没有聚焦时都被按下。我希望它只会在我单击按钮本身时触发。我尝试搜索 Google 和 StackOverflow,但没有找到与我的问题相关的任何内容。
奇怪的是,确切的行为有所不同。有时,单击特定区域中的按钮也会触发它旁边的按钮。其他时候,除了我实际按下的按钮之外,当我单击窗口内的任意位置时,会触发一个按钮(看似随机选择并保持不变,直到我停止程序)。在窗口外单击总是只触发最近的按钮。
我的 MRE 是:
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()
我的外壳输出是:
[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��>
没有按下任何内容的窗口(我没有足够的声誉来发布图像,所以它是一个链接):
万一它是相关的,我正在运行一个带有 32 位 Raspberry Pi OS 的 8gb pi 4。
解决方案
推荐阅读
- python - SSL 错误:使用 psycopg 解密失败或错误记录 mac
- rest - HTTP和Rest有什么关系?
- swift - 如何在单击分段控件之前对视图进行更改?
- delphi-xe3 - Delphi - SQL Server 查询需要很长时间才能运行
- types - 为什么我会因为缺少类型注释而收到错误“特征绑定 FromStr 不满足”?
- django - 子类化基于类的视图时没有httpresponse
- dart - 强制用户显式声明变量
- ruby-on-rails - Rails 6 ActionCable/Redis 生产配置
- laravel - 如何获取当前动作(方法)名称?
- java - 在外部 Tomcat 服务器上运行的 Springboot 在除 index.html 之外的所有内容上都会出现错误 404