Why does this Scrollbar malfunction in fullscreen on certain versions of Tk only?

Viewed 50

There are many, many questions on Stackoverflow and the internet about tkinter Scrollbars and Canvases, and all of their answers I've ever seen before boil down to configuring them properly, which makes it hard to find uncommon Scrollbar questions. I've constructed an almost-working 2D scrolling canvas for an application I'm making, but I have a strange problem I've never seen mentioned (possibly specific to Macs and/or some Tk versions). Here's some simplified code which doesn't include any of the maxsize/minsize, <Configure> and other event bindings, and other weird stuff my main window does but which demonstrates it nonetheless (for Python 2 and 3 both):

try:
    import tkinter
except ImportError:
    import Tkinter as tkinter

t = tkinter.Tk()
# Force no highlightthickness so borders are not cut off
canvas = tkinter.Canvas(t, width=500, height=500, highlightthickness=0)
xbar = tkinter.Scrollbar(t, orient='horizontal', command=canvas.xview, width=10)
ybar = tkinter.Scrollbar(t, orient='vertical', command=canvas.yview, width=10)
canvas.config(xscrollcommand=xbar.set, yscrollcommand=ybar.set)
# This could be in the constructor but this is just to highlight it
canvas.config(scrollregion=(0, 0, 1000, 1000))
canvas.grid(row=0, column=0)
ybar.grid(row=0, column=1, sticky='ns')
xbar.grid(row=1, column=0, sticky='ew')

# Draw test pattern to make sure the scrolling works, section can be removed
canvas.config(bg='#44a')
for y in range(0, 1000, 50):
    for x in range(0, 1000, 50):
        canvas.create_oval(x, y, x + 20, y + 20, fill='#e66' * (x + y > 1000))

t.mainloop()

On the Mac built-in Tcl/Tk 8.5, these Scrollbars turn darker-gray when hovered and dragged, which is intended (though they don't turn back to light-gray until later, weirdly), and they both work, even in fullscreen mode (entered by clicking the green window button, or the View -> Enter Full Screen menu option when my application's custom menu is active)

On my newer Tcl/Tk 8.5 (which is why I use Python 3.6.4), these Scrollbars don't turn darker-gray, and both work in windowed mode, but only the Y Scrollbar works in fullscreen mode. The X Scrollbar will stay in place, keeping its position from windowed mode.

This is a very strange glitch, and I'm not sure why it happens. It doesn't seem like I've messed up the setup, according to docs and guides I found, but if there's anything I'm missing, let me know. It'd be nice to have a foolproof cross-platform Python and Tk version independent tkinter solution, but I'd also settle for a quick hack just for this, if possible. I've already tried the Scrollbar config option takefocus=0 and a few other things, including not using mainloop() and updating the window more or less.

There's also a good reason I'm still using Tk 8.5 too, but it would be great if this wasn't a problem in the new bundled 8.6. I'll test it soon.

Thanks for your help!

0 Answers
Related