Reputation: 307
I would like to lay an invisible scrollbar over a Treeview I am using a raspberry pi and have a small touchscreen and I thus would like to use the space efficiently I had to size up my scrollbar as I couldn't figure out how to make "swipe"-scrolling in a treeview possible That's why I now have very little space and the font is almost too small Is there any way to make a scrollbar invisible, but still usable when laying on another widget with eg. the place function?
Upvotes: 0
Views: 419
Reputation: 385880
You don't need scrollbars to scroll. All scrollable widgets have an api that is used for scrolling: the xview
and yview
methods. The scrollbar is just a convenient way to call those methods, but it's not the only way.
I don't know what events a swipe will send, but you can bind to those events and directly call the xview
and/or yview
methods yourself.
For example, let's assume for the moment that a touch is the <B1>
event, and a swipe is the <B1-Motion>
event. You can scroll with a swiping motion like this:
class Example:
def __init__(self):
...
self.tree = ttk.Treeview(...)
self.tree.bind("<B1>", self.start_swipe)
self.tree.bind("<B1-Motion>", self.on_swipe)
...
def start_swipe(self, event):
self.last_y = event.y
def on_swipe(self, event):
# only do the scrolling if the swipe is 10 pixels or more
if abs(event.y - self.swipe_start) < 10:
return
# compute whether we are scrolling up or down
delta = -1 if event.y > self.last_y else 1
# remember this location for the next time this is called
self.last_y = event.y
# do the scroll
self.tree.yview_scroll(delta, "units")
Upvotes: 2