<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Juan,<div class=""><br class=""></div><div class="">I installed ActiveTCL8.5.18 as described on <a href="https://www.python.org/download/mac/tcltk/" class="">python.org's Tcl/Tk page for macOS</a> and now the script runs under python3.6 without errors when scrolling with the trackpad.  If your usage allows, you should consider installing a newer version of Tcl/Tk if you are using <a href="http://python.org" class="">python.org</a>'s python or switch to Anaconda's python.</div><div class=""><br class=""></div><div class="">Scott<br class=""><div class=""><br class=""></div><div class=""><br class=""><blockquote type="cite" class="">On Jan 10, 2017, at 11:33 AM, Ryan May <<a href="mailto:rmay31@gmail.com" class="">rmay31@gmail.com</a>> wrote:<br class=""><br class="">Works for me on macOS 10.12.2, Python 3.5.2 (conda-forge) and matplotlib 2.0rc2.<br class=""><br class="">Ryan<br class=""><br class="">On Tue, Jan 10, 2017 at 12:48 AM, Scott Lasley <<a href="mailto:selasley@icloud.com" class="">selasley@icloud.com</a>> wrote:<br class="">I get the error when running under python3.6 and scrolling with the trackpad.<br class="">OS X 10.12.2 with the system installed Tk version 8.5, python 3.6.0, matplotlib 2.0.0rc2+2939.g109251f<br class=""><br class="">Traceback (most recent call last):<br class="">  File "<stdin>", line 1, in <module><br class="">  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/pyplot.py", line 252, in show<br class="">    return _show(*args, **kw)<br class="">  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/backend_bases.py", line 188, in __call__<br class="">    self.mainloop()<br class="">  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/backends/backend_tkagg.py", line 71, in mainloop<br class="">    Tk.mainloop()<br class="">  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/tkinter/__init__.py", line 557, in mainloop<br class="">    _default_root.tk.mainloop(n)<br class="">UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte<br class="">>>> UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte<br class=""><br class=""><br class="">The script works when run under python 2.7.13 and scrolling with the trackpad.<br class=""><br class=""><br class="">> On Jan 9, 2017, at 23:40, Thomas Caswell <tcaswell@gmail.com> wrote:<br class="">><br class="">> I can not reproduce this on linux :/<br class="">><br class="">> This looks like it is coming out of Tk's handling of the scroll event before it is handed off to mpl.<br class="">><br class="">> Tom<br class="">><br class="">> On Mon, Jan 9, 2017 at 10:28 PM Juan Nunez-Iglesias <jni.soma@gmail.com> wrote:<br class="">> Hi all,<br class="">><br class="">> 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.)<br class="">><br class="">> 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:<br class="">><br class="">> Traceback (most recent call last):<br class="">>   File "basic_mpl_connect.py", line 20, in <module><br class="">>     plt.show()<br class="">>   File "/Users/jni/conda/envs/ana/lib/python3.5/site-packages/matplotlib/pyplot.py", line 252, in show<br class="">>     return _show(*args, **kw)<br class="">>   File "/Users/jni/conda/envs/ana/lib/python3.5/site-packages/matplotlib/backend_bases.py", line 192, in __call__<br class="">>     self.mainloop()<br class="">>   File "/Users/jni/conda/envs/ana/lib/python3.5/site-packages/matplotlib/backends/backend_tkagg.py", line 74, in mainloop<br class="">>     Tk.mainloop()<br class="">>   File "/Users/jni/conda/envs/ana/lib/python3.5/tkinter/__init__.py", line 405, in mainloop<br class="">>     _default_root.tk.mainloop(n)<br class="">> UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte<br class="">><br class="">> This is true even if I explicitly connect the “scroll_event” (below).<br class="">><br class="">> Any ideas?<br class="">><br class="">> Thanks,<br class="">><br class="">> Juan.<br class="">><br class="">> ===================================<br class="">><br class="">> import matplotlib<br class="">> matplotlib.use('TkAgg')<br class="">> matplotlib.verbose.level = 'debug'<br class="">> import matplotlib.pyplot as plt<br class="">><br class="">> def process_key(event):<br class="">>     print("Key:", event.key)<br class="">><br class="">> def process_button(event):<br class="">>     print("Button:", event.x, event.y, event.xdata, event.ydata, event.button)<br class="">><br class="">> def process_scroll(event):<br class="">>     print("Scroll")<br class="">><br class="">> fig, ax = plt.subplots(1, 1)<br class="">> fig.canvas.mpl_connect('key_press_event', process_key)<br class="">> fig.canvas.mpl_connect('button_press_event', process_button)<br class="">> fig.canvas.mpl_connect('scroll_event', process_scroll)<br class="">> plt.show()<br class="">> _______________________________________________<br class="">> Matplotlib-users mailing list<br class="">> Matplotlib-users@python.org<br class="">> https://mail.python.org/mailman/listinfo/matplotlib-users<br class=""><br class="">-- <br class="">Ryan May<br class=""><br class=""></blockquote><br class=""></div></div></body></html>