1
我構建了一個小圖形用GUI顯示一些帶有kivy的實時數據。在kivy中觸摸(單擊)matplotlib圖形會崩潰
我加入了matplotlib圖在我的屏幕上做這個:
fig, ax = plt.subplots()
plt.plot([1,2])
canvas = fig.canvas
self.ids.screen.add_widget(canvas, 2)
的GUI的其餘部分設計有.kv
文件。一切工作正常,但如果我不小心碰的情節發生這種情況並沒有進一步的接觸是可能的:
[INFO ] [Base ] Leaving application in progress...
Traceback (most recent call last):
File "main.py", line 167, in <module>
TestApp().run()
File "/usr/local/lib/python3.4/dist-packages/kivy/app.py", line 828, in run
runTouchApp()
File "/usr/local/lib/python3.4/dist-packages/kivy/base.py", line 487, in runTouchApp
EventLoop.window.mainloop()
File "/usr/local/lib/python3.4/dist-packages/kivy/core/window/window_egl_rpi.py", line 89, in mainloop
self._mainloop()
File "/usr/local/lib/python3.4/dist-packages/kivy/core/window/window_egl_rpi.py", line 84, in _mainloop
EventLoop.idle()
File "/usr/local/lib/python3.4/dist-packages/kivy/base.py", line 330, in idle
self.dispatch_input()
File "/usr/local/lib/python3.4/dist-packages/kivy/base.py", line 315, in dispatch_input
post_dispatch_input(*pop(0))
File "/usr/local/lib/python3.4/dist-packages/kivy/base.py", line 221, in post_dispatch_input
listener.dispatch('on_motion', etype, me)
File "kivy/_event.pyx", line 718, in kivy._event.EventDispatcher.dispatch (/tmp/pip-a56bsdeu-build/kivy/_event.c:7726)
File "/usr/local/lib/python3.4/dist-packages/kivy/core/window/__init__.py", line 1070, in on_motion
self.dispatch('on_touch_down', me)
File "kivy/_event.pyx", line 718, in kivy._event.EventDispatcher.dispatch (/tmp/pip-a56bsdeu-build/kivy/_event.c:7726)
File "/usr/local/lib/python3.4/dist-packages/kivy/core/window/__init__.py", line 1086, in on_touch_down
if w.dispatch('on_touch_down', touch):
File "kivy/_event.pyx", line 718, in kivy._event.EventDispatcher.dispatch (/tmp/pip-a56bsdeu-build/kivy/_event.c:7726)
File "/usr/local/lib/python3.4/dist-packages/kivy/uix/widget.py", line 457, in on_touch_down
if child.dispatch('on_touch_down', touch):
File "kivy/_event.pyx", line 718, in kivy._event.EventDispatcher.dispatch (/tmp/pip-a56bsdeu-build/kivy/_event.c:7726)
File "/usr/local/lib/python3.4/dist-packages/kivy/uix/widget.py", line 457, in on_touch_down
if child.dispatch('on_touch_down', touch):
File "kivy/_event.pyx", line 718, in kivy._event.EventDispatcher.dispatch (/tmp/pip-a56bsdeu-build/kivy/_event.c:7726)
File "/home/sysop/.kivy/garden/garden.matplotlib/backend_kivy.py", line 1067, in on_touch_down
if(touch.button == "scrollup" or touch.button == "scrolldown"):
AttributeError: 'MTDMotionEvent' object has no attribute 'button'
什麼是避免這種情況的最好方法是什麼?
請使用更專業術語像鼠標懸停或點擊,而不是觸摸。 – MYGz
對不起,我使用觸摸屏。因此,我寫了觸摸。 – Philipp
哦,對不起,我的壞。在快速閱讀中沒有注意「Kivy」。 – MYGz