Event connect error when using Tk and scrolling

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
jni
Reply | Threaded
Open this post in threaded view
|

Event connect error when using Tk and scrolling

jni
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
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Event connect error when using Tk and scrolling

tcaswell
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 <[hidden email]> 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
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users

_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Event connect error when using Tk and scrolling

Scott Lasley-2
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 <[hidden email]> 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 <[hidden email]> 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
> [hidden email]
> https://mail.python.org/mailman/listinfo/matplotlib-users
> _______________________________________________
> Matplotlib-users mailing list
> [hidden email]
> https://mail.python.org/mailman/listinfo/matplotlib-users

_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Event connect error when using Tk and scrolling

Ryan May-3
Works for me on macOS 10.12.2, Python 3.5.2 (conda-forge) and matplotlib 2.0rc2.

Ryan

On Tue, Jan 10, 2017 at 12:48 AM, Scott Lasley <[hidden email]> wrote:
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 <[hidden email]> 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 <[hidden email]> 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
> [hidden email]
> https://mail.python.org/mailman/listinfo/matplotlib-users
> _______________________________________________
> Matplotlib-users mailing list
> [hidden email]
> https://mail.python.org/mailman/listinfo/matplotlib-users

_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users



--
Ryan May


_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Event connect error when using Tk and scrolling

Scott Lasley-2
Juan,

I installed ActiveTCL8.5.18 as described on python.org's Tcl/Tk page for macOS 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 python.org's python or switch to Anaconda's python.

Scott


On Jan 10, 2017, at 11:33 AM, Ryan May <[hidden email]> wrote:

Works for me on macOS 10.12.2, Python 3.5.2 (conda-forge) and matplotlib 2.0rc2.

Ryan

On Tue, Jan 10, 2017 at 12:48 AM, Scott Lasley <[hidden email]> wrote:
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 <[hidden email]> 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 <[hidden email]> 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
[hidden email]
> https://mail.python.org/mailman/listinfo/matplotlib-users

-- 
Ryan May



_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
jni
Reply | Threaded
Open this post in threaded view
|

Re: Event connect error when using Tk and scrolling

jni
Hi all,

Thanks for taking a look. Unfortunately I don’t have time right now to test with a new version of Anaconda Python, but I should mention that the original error reported was using Anaconda + Python 3.5, mpl 1.5.

Will give it another go tomorrow with an updated anaconda distro, and maybe check out the latest ActiveTCL if relevant.

Thanks!

Juan.

On 11 Jan 2017, 8:56 AM +1100, Scott Lasley <[hidden email]>, wrote:
Juan,

I installed ActiveTCL8.5.18 as described on python.org's Tcl/Tk page for macOS 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 python.org's python or switch to Anaconda's python.

Scott


On Jan 10, 2017, at 11:33 AM, Ryan May <[hidden email]> wrote:

Works for me on macOS 10.12.2, Python 3.5.2 (conda-forge) and matplotlib 2.0rc2.

Ryan

On Tue, Jan 10, 2017 at 12:48 AM, Scott Lasley <[hidden email]> wrote:
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 <[hidden email]> 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 <[hidden email]> 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
[hidden email]
> https://mail.python.org/mailman/listinfo/matplotlib-users

-- 
Ryan May



_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
jni
Reply | Threaded
Open this post in threaded view
|

Re: Event connect error when using Tk and scrolling

jni
In reply to this post by Scott Lasley-2
Hmm, installing ActiveTCL didn't help when using Anaconda Python. Which makes sense, but it was worth a shot. =)

On 11 Jan 2017, 8:56 AM +1100, Scott Lasley <[hidden email]>, wrote:
Juan,

I installed ActiveTCL8.5.18 as described on python.org's Tcl/Tk page for macOS 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 python.org's python or switch to Anaconda's python.

Scott


On Jan 10, 2017, at 11:33 AM, Ryan May <[hidden email]> wrote:

Works for me on macOS 10.12.2, Python 3.5.2 (conda-forge) and matplotlib 2.0rc2.

Ryan

On Tue, Jan 10, 2017 at 12:48 AM, Scott Lasley <[hidden email]> wrote:
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 <[hidden email]> 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 <[hidden email]> 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
[hidden email]
> https://mail.python.org/mailman/listinfo/matplotlib-users

-- 
Ryan May



_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Event connect error when using Tk and scrolling

Scott Lasley-2
I installed the python 3.5 version of anaconda 4.2.0.  The  conda list  command shows tk 8.5.18 installed, but
tkinter.Tk().eval('info patchlevel') returns 8.5.9.  It looks like tkinter is hard coded to use the system installed Tk and Tcl libraries as shown by the output of
otool -L anaconda/lib/python3.5/lib-dynload/_tkinter.so
otool -L anaconda/pkgs/python-3.5.2-0/lib/python3.5/lib-dynload/_tkinter.so

This stackoverflow answer lead me to a possible solution -
http://stackoverflow.com/questions/35593602/tk-framework-double-implementation-issue/37222391

After using the commands below in Terminal to change the path to libtk8 and libtcl8 that tkinter uses,
tkinter.Tk().eval('info patchlevel') returns 8.5.18 and your script runs without errors when scrolling.  It does output a couple of deprecation warnings when it first runs.  Mucking with library paths like this is not a great solution.  Your best bet might be to contact support at contimuum or ask about this problem on their anaconda mailing list.

Here are the commands I ran to update the tkinter paths (you may need to have the command line developer tools installed):

install_name_tool -change \
"/System/Library/Frameworks/Tk.framework/Versions/8.5/Tk" \
"@loader_path/../../libtk8.5.dylib" \
anaconda/lib/python3.5/lib-dynload/_tkinter.so

install_name_tool -change \
"/System/Library/Frameworks/Tcl.framework/Versions/8.5/Tcl" \
"@loader_path/../../libtcl8.5.dylib" \
anaconda/lib/python3.5/lib-dynload/_tkinter.so

install_name_tool -change \
"/System/Library/Frameworks/Tk.framework/Versions/8.5/Tk" \
"@loader_path/../../libtk8.5.dylib" \
anaconda/pkgs/python-3.5.2-0/lib/python3.5/lib-dynload/_tkinter.so

install_name_tool -change \
"/System/Library/Frameworks/Tcl.framework/Versions/8.5/Tcl" \
"@loader_path/../../libtcl8.5.dylib" \
anaconda/pkgs/python-3.5.2-0/lib/python3.5/lib-dynload/_tkinter.so

hth,
Scott

> On Jan 17, 2017, at 01:09, Juan Nunez-Iglesias <[hidden email]> wrote:
>
> Hmm, installing ActiveTCL didn't help when using Anaconda Python. Which makes sense, but it was worth a shot. =)
>
> On 11 Jan 2017, 8:56 AM +1100, Scott Lasley <[hidden email]>, wrote:
>> Juan,
>>
>> I installed ActiveTCL8.5.18 as described on python.org's Tcl/Tk page for macOS 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 python.org's python or switch to Anaconda's python.
>>
>> Scott
>>
>>
>>> On Jan 10, 2017, at 11:33 AM, Ryan May <[hidden email]> wrote:
>>>
>>> Works for me on macOS 10.12.2, Python 3.5.2 (conda-forge) and matplotlib 2.0rc2.
>>>
>>> Ryan
>>>
>>> On Tue, Jan 10, 2017 at 12:48 AM, Scott Lasley <[hidden email]> wrote:
>>> 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 <[hidden email]> 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 <[hidden email]> 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
>>> > [hidden email]
>>> > https://mail.python.org/mailman/listinfo/matplotlib-users
>>>
>>> --
>>> Ryan May
>>>
>>

_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users