pysimplegui - 用于向下滚动的按钮
pysimplegui -button for scrolling all the way down
我正在使用 pysimplegui 构建一个图形用户界面,其中包含许多输入框,如下所示:
为了给用户一个舒适的导航体验,我添加了向下和向上按钮,它们的目的是根据按下的按钮向下或向上移动滚动条:
form = sg.Window('analysis').Layout([
[sg.Column(layout, size=(width / 3, height / 2), scrollable=True, key = "Column")],
[sg.OK(), sg.Button('Up', key = "up"), sg.Button('Down', key = "down")]
])
这段代码基本上是在创建 window,里面有一个列元素,里面有一个预先创建的布局(包含里面的所有输入框),一个带有预先创建的大小的大小,启用了 scorllable 和一个我想用来控制滚动条的位置。
另一行包含所有讨论过的按钮。
之后我创建了一个循环来管理触发时的所有事件:
while True:
event, values = form.read()
if(event == sg.WIN_CLOSED):
break
elif(event == "down"):
form.Element('Column').set_vscroll_position(1.0)
elif(enent == "up"):
form.Element('Column').set_vscroll_position(0.0)
按钮没有按计划运行,当触发时跳出警告:
Warning setting the vertical scroll (yview_moveto failed)
'TkScrollableFrame' object has no attribute 'yview_moveto
好像我按照pysimplegui 的文档做了一切,但它不起作用。
任何帮助将不胜感激。
感谢,尊重,革命。
操作系统:Windows10
Python版本:3.8.1
通过 github 联系 pysimplegui 和其他贡献者后,对警告的解释如下:
Columns are special and will need some additional code done in order to manipulate their scrollbars. Didn't think to document / handle this element. The code operates on the "Widget" and the Column element on its own isn't a standalone Widget like some of the others with scrollbars.
此外还以 tkinter 调用和 trates 的形式提供了解决方案:
import PySimpleGUI as sg
font = ('Courier New', 16)
text = '\n'.join(chr(i)*50 for i in range(65, 91))
column = [[sg.Text(text, font=font)]]
layout = [
[sg.Column(column, size=(800, 300), scrollable=True, key = "Column")],
[sg.OK(), sg.Button('Up', key = "up"), sg.Button('Down', key = "down")],
]
window = sg.Window('Demo', layout, finalize=True)
while True:
event, values = window.read()
if event == sg.WIN_CLOSED:
break
elif event == "down":
window['Column'].Widget.canvas.yview_moveto(1.0)
elif event == "up":
window['Column'].Widget.canvas.yview_moveto(0.0)
window.close()
我正在使用 pysimplegui 构建一个图形用户界面,其中包含许多输入框,如下所示:
为了给用户一个舒适的导航体验,我添加了向下和向上按钮,它们的目的是根据按下的按钮向下或向上移动滚动条:
form = sg.Window('analysis').Layout([
[sg.Column(layout, size=(width / 3, height / 2), scrollable=True, key = "Column")],
[sg.OK(), sg.Button('Up', key = "up"), sg.Button('Down', key = "down")]
])
这段代码基本上是在创建 window,里面有一个列元素,里面有一个预先创建的布局(包含里面的所有输入框),一个带有预先创建的大小的大小,启用了 scorllable 和一个我想用来控制滚动条的位置。
另一行包含所有讨论过的按钮。
之后我创建了一个循环来管理触发时的所有事件:
while True:
event, values = form.read()
if(event == sg.WIN_CLOSED):
break
elif(event == "down"):
form.Element('Column').set_vscroll_position(1.0)
elif(enent == "up"):
form.Element('Column').set_vscroll_position(0.0)
按钮没有按计划运行,当触发时跳出警告:
Warning setting the vertical scroll (yview_moveto failed) 'TkScrollableFrame' object has no attribute 'yview_moveto
好像我按照pysimplegui 的文档做了一切,但它不起作用。 任何帮助将不胜感激。
感谢,尊重,革命。
操作系统:Windows10 Python版本:3.8.1
通过 github 联系 pysimplegui 和其他贡献者后,对警告的解释如下:
Columns are special and will need some additional code done in order to manipulate their scrollbars. Didn't think to document / handle this element. The code operates on the "Widget" and the Column element on its own isn't a standalone Widget like some of the others with scrollbars.
此外还以 tkinter 调用和 trates 的形式提供了解决方案:
import PySimpleGUI as sg
font = ('Courier New', 16)
text = '\n'.join(chr(i)*50 for i in range(65, 91))
column = [[sg.Text(text, font=font)]]
layout = [
[sg.Column(column, size=(800, 300), scrollable=True, key = "Column")],
[sg.OK(), sg.Button('Up', key = "up"), sg.Button('Down', key = "down")],
]
window = sg.Window('Demo', layout, finalize=True)
while True:
event, values = window.read()
if event == sg.WIN_CLOSED:
break
elif event == "down":
window['Column'].Widget.canvas.yview_moveto(1.0)
elif event == "up":
window['Column'].Widget.canvas.yview_moveto(0.0)
window.close()