我在我的kv文件中使用了scroll_to函数。它可以根据需要正确滚动,但是如果我转动鼠标滚轮,它会在scroll_to()之前跳回原位。
任何想法,我怎样才能改进我的代码?
我的kv文件的snipplet:
MyButton:
text: 'jump'
on_release: scroll_content.scroll_to(jump_id_2, padding=0, animate=True)
ScrollView:
id: scroll_content
blah, blah, blah.......
# values of the devices
GridLayout:
BoxLayout:
id: jump_id_0
blah, blah, blah.......
BoxLayout:
id: jump_id_1
blah, blah, blah.......
BoxLayout:
id: jump_id_2
blah, blah, blah.......
感谢您的帮助......
答案 0 :(得分:0)
我设法找到了一个“解决方案”:基本上你在“内容”上设置了scroll_type, 然后点击屏幕上的某个地方......
MyButton:
text: 'jump'
on_release: scroll_content.scroll_to(jump_id_2, padding=0, animate=True); app.click(200)
ScrollView:
id: scroll_content
scroll_type: ['content']
blah, blah, blah.......
# values of the devices
GridLayout:
BoxLayout:
id: jump_id_0
blah, blah, blah.......
BoxLayout:
id: jump_id_1
blah, blah, blah.......
BoxLayout:
id: jump_id_2
blah, blah, blah.......
点击功能是:
def click(self, shift):
"""Click on the screen."""
pt = POINT()
ctypes.windll.user32.GetCursorPos(ctypes.byref(pt))
ctypes.windll.user32.SetCursorPos(pt.x, pt.y + shift)
ctypes.windll.user32.mouse_event(2, pt.x, pt.y + shift, 0, 0)
ctypes.windll.user32.mouse_event(4, pt.x, pt.y + shift, 0, 0)
ctypes.windll.user32.SetCursorPos(pt.x, pt.y)