[Matplotlib-users] Event connect error when using Tk and scrolling

Scott Lasley selasley at icloud.com
Tue Jan 10 02:48:47 EST 2017


I get the error when running under python3.6 and scrolling with the trackpad.
OS X 10.12.2 with the system installed Tk version 8.5, python 3.6.0, matplotlib 2.0.0rc2+2939.g109251f

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/pyplot.py", line 252, in show
    return _show(*args, **kw)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/backend_bases.py", line 188, in __call__
    self.mainloop()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/backends/backend_tkagg.py", line 71, in mainloop
    Tk.mainloop()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/tkinter/__init__.py", line 557, in mainloop
    _default_root.tk.mainloop(n)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
>>> UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte


The script works when run under python 2.7.13 and scrolling with the trackpad.


> On Jan 9, 2017, at 23:40, Thomas Caswell <tcaswell at gmail.com> wrote:
> 
> I can not reproduce this on linux :/
> 
> This looks like it is coming out of Tk's handling of the scroll event before it is handed off to mpl.
> 
> Tom
> 
> On Mon, Jan 9, 2017 at 10:28 PM Juan Nunez-Iglesias <jni.soma at gmail.com> wrote:
> Hi all,
> 
> I’m trying to play with the `basic_mpl_connect.py` example from Ben Root’s “Interactive Applications Using Matplotlib” book, reproduced below in its entirety. (With the addition of selecting TkAgg as the backend. I need to do this because I’m aiming to embed into a Tk app *and* the MacOSX backend doesn’t capture my keystrokes.)
> 
> Everything works fine, but when I try to use the scroll wheel on my mouse, or two-finger scrolling on my Macbook trackpad, everything dies with the following message:
> 
> Traceback (most recent call last):
>   File "basic_mpl_connect.py", line 20, in <module>
>     plt.show()
>   File "/Users/jni/conda/envs/ana/lib/python3.5/site-packages/matplotlib/pyplot.py", line 252, in show
>     return _show(*args, **kw)
>   File "/Users/jni/conda/envs/ana/lib/python3.5/site-packages/matplotlib/backend_bases.py", line 192, in __call__
>     self.mainloop()
>   File "/Users/jni/conda/envs/ana/lib/python3.5/site-packages/matplotlib/backends/backend_tkagg.py", line 74, in mainloop
>     Tk.mainloop()
>   File "/Users/jni/conda/envs/ana/lib/python3.5/tkinter/__init__.py", line 405, in mainloop
>     _default_root.tk.mainloop(n)
> UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
> 
> This is true even if I explicitly connect the “scroll_event” (below).
> 
> Any ideas?
> 
> Thanks,
> 
> Juan.
> 
> ===================================
> 
> import matplotlib
> matplotlib.use('TkAgg')
> matplotlib.verbose.level = 'debug'
> import matplotlib.pyplot as plt
> 
> def process_key(event):
>     print("Key:", event.key)
> 
> def process_button(event):
>     print("Button:", event.x, event.y, event.xdata, event.ydata, event.button)
> 
> def process_scroll(event):
>     print("Scroll")
> 
> fig, ax = plt.subplots(1, 1)
> fig.canvas.mpl_connect('key_press_event', process_key)
> fig.canvas.mpl_connect('button_press_event', process_button)
> fig.canvas.mpl_connect('scroll_event', process_scroll)
> plt.show()
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users at python.org
> https://mail.python.org/mailman/listinfo/matplotlib-users
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users at python.org
> https://mail.python.org/mailman/listinfo/matplotlib-users



More information about the Matplotlib-users mailing list