0

There is a weird GUI bug in tkinter on the interaction between the mouse pointer and a tkinter.Scrollbar. The slider of the scrollbar is not at the location shown graphically and it doesn't move at the same speed as the mouse pointer sliding. It makes it very difficult to use. Here is a sample code, borrowed from http://effbot.org/tkinterbook/scrollbar.htm:

#!/usr/bin/env python3 # python 3.4.3 using ActiveTcl 8.5.18
#!/usr/bin/env python # python 2.7.10 using ActiveTcl 8.5.18
#!/usr/bin/python # os-x-native python 2.7.5 using os-x-native Tcl 8.5.9 [WORKS]

# Example from http://effbot.org/tkinterbook/scrollbar.htm
try:
    # Python2
    import Tkinter as tk

except ImportError:
    # Python3
    import tkinter as tk
    import tkinter.ttk as ttk

import sys

master = tk.Tk()

# print version info:
sys.stdout.write("Python: %s.%s.%s\nTcl: %s\n" % (sys.version_info[0], sys.version_info[1], sys.version_info[2], tk.Tcl().eval("info patchlevel")))

# scrollbar = ttk.Scrollbar(master)
scrollbar = tk.Scrollbar(master)
scrollbar.pack(side=tk.RIGHT, fill=tk.Y)

listbox = tk.Listbox(master, yscrollcommand=scrollbar.set)
for i in range(1000):
    listbox.insert(tk.END, str(i))
listbox.pack(side=tk.LEFT, fill=tk.BOTH)

scrollbar.config(command=listbox.yview)

tk.mainloop()

Try to click-and-drag the slider: it doesn't work. If you click-and-drag below the slider, then it works. It looks like the mouse-reactive slider doesn't correspond to the visual slider. Also, the speed at which the slider moves when dragging doesn't correspond to the mouse speed...

This only occurs on mac using ActiveTcl 8.5.18 (the recommended version on mac for Python >= 2.7.10 including Python 3). Everything works fine when using the osx-native python 2.7.5 and osx-native Tcl 8.5.9 (os x 10.9.5).

The problem is absent on linux with python 3.4.3 and Tcl 8.6.1, not sure on windows.

Would anyone know a workaround/fix? Using the themed-widget version of Scrollbar doesn't resolve the problem.

armando.sano
  • 345
  • 1
  • 3
  • 9
  • How are you running tkinter with Active**Tcl**? I have ActiveTcl and ActivePython installed on my OSX box and your code works fine for me. – Bryan Oakley Jan 15 '16 at 11:50
  • @BryanOakley: not sure what you mean. I basically installed ActiveTcl and python 2.7.10 and 3 from python.org, as described [there](https://www.python.org/download/mac/tcltk). I have no other installation of Tcl/Tk than the "osx-native" one (8.5.9) and ActiveTcl's (8.5.18), so I guess when I use tkinter with python 3 and it tells me the version number is 8.5.18 it must be ActiveTcl's... Good to know everything works with ActivePython though! I wonder what creates the problem then! – armando.sano Jan 16 '16 at 11:26

1 Answers1

0

This is not a bug in tkinter, but a bug in the Mac implementation of Tk, starting with version 8.5.18 and 8.6.4. In these two versions the native scrollbar was removed because the Cocoa scrolling management had all kinds of hidden issues with Tk. The scrollbar is now drawn using HItheme, but this introduced the described offset between the visual slider and the area that acts like the slider. There is currently no fix for this. See here for more details:

https://sourceforge.net/p/tcl/mailman/tcl-mac/?viewmonth=201703

  • thanks for tracking this bug down to the mac implementation of Tk. I am only intrigued about the fact that it didn't seem to affect ActiveTcl with ActivePython (comment by BryanOakley above) – armando.sano Apr 12 '17 at 04:02