我想在我的 RPi 上创建 GUI,以便我可以像在 iPhone 中一样滚动列表框,而无需使用滚动条。换句话说,只需触摸列表框并向上/向下“轻拂”手指,我希望能够滚动。
这种滚动方法可以使用 TKinter 或任何 RPi 的 GUI 来完成吗?
最佳答案
是的。
看看滚动条的绑定(bind)是如何工作的。
怎样才能达到想要的效果呢? Bin Mouse-Move 事件(触摸移动就是别的)并使用它来将其连接到 yview/xview,具体取决于您想要的滚动。
(例如,检查鼠标在回调中移动的方向,并使用该信息触发滚动事件。)
如果需要进一步帮助,请告诉我们。
编辑:
这里有一些“虚拟代码”...
# this is your callback bound to mouse-move event
def mouse_move_callback(event):
# use event.y with a previous remembered y value to determine
# directions
directions = 1 # just as an example, could also be -1
# scroll the listbox vertically.
# to increase scrolling speed, either multiply counter by some value >1
# or replace 'units' which means scroll 1 character in the current setting
# by 'pages' for larger steps. 'pages' should scroll the visible
# area of the listbox further.
listbox.yview_scroll(1, 'units')
您还可以使用鼠标按钮按下和鼠标按钮释放来触发操作。按下鼠标按钮将存储 y 值(滚动开始),并且释放鼠标按钮将绑定(bind)到上述回调。
关于python - 是否可以在没有滚动条的情况下滚动 Tkinter 列表框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38196401/