I am working on a Python 3.3 project that uses Tkinter as a Window manager. I have mouse scroll wheel events set up for a canvas. The scrolling works in Windows 7, 8, and Ubuntu, but upon scrolling with a Magic Mouse in Mac OS X Mountain Lion, the program crashes with teh following error in the Tk main loop:
File "/Users/xxxx/Documents/Repositories/tycoon/agentsim.py", line 291, in start
self._root.mainloop()
File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/tkinter/__init__.py", line 1038, in mainloop
self.tk.mainloop(n)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe7 in position 0: invalid continuation byte
My code was:
self._hscroll.configure( command=self._canvas.xview )
self._vscroll.configure( command=self._canvas.yview )
self._canvas.bind('<MouseWheel>', lambda event: self.rollWheel(event))
where hscroll and vscroll are scrollbar objects in the form.
If I use a regular mouse, the problem doesn't occur. It also occurs when I try scroll with my trackpad (with inertial scrolling turned on)
Do I have to update Tk to make this functionality work, or is it just broken in general?
with inertia: Scrolling comes to a gradual stop. without inertia: Scrolling stops immediately.
If you are using a Python from any current python.org Python installer for macOS (3.10. 0+ or 3.9. 0+), no further action is needed to use IDLE or tkinter. A built-in version of Tcl/Tk 8.6 will be used.
These errors can be caught:
while True:
try:
root.mainloop()
break
except UnicodeDecodeError:
pass
This seems to work perfectly, even scrolling inertially, and does not require any installation/upgrading.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With