The following has only been tested on Windows, other OS's may vary.
For any future readers, since Tk 8.5, Treeviews have an identify_region
method that accepts a screen position (x,y) and will return a string corresponding to the region of the treeview those coordinates occupy.
One of the return values is "separator".
I've used this to catch double-click events on the separator to auto-size columns, but you could also use it to catch single-click events and block them.
For example:
def handle_click(event):
if treeview.identify_region(event.x, event.y) == "separator":
return "break"
#...
treeview.bind('<Button-1>', handle_click)
This has the advantage of not rendering the entire treeview disabled -- so you can still select/expand/collapse rows, click column headings to sort, etc -- you just won't be able to resize the columns.
Note that even though resizing is disabled, the "double arrow" cursor (⇔) will still appear. You could additionally prevent the double arrow cursor from showing by doing the exact same thing with the <Motion>
event (binding to it, checking if it's above a separator, and stopping the event from being propagated by returning the string "break"
).
>>> sys.version
'3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit (AMD64)]'
>>> tkinter.TkVersion
8.6
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…