Reputation: 169
I'm building a gui using pysimplegui which contains lots of input boxes as shown bellow:
In order to give the user a comfortable navigation experience I have added the buttons Down and Up which their purpose is move the scroll all the way down or up according to the pressed button:
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")]
])
This code is basically creating The window with a column element inside with a pre created layout (containing all of the input boxes inside), a size with pre created sizes, scorllable enabled and a key which I want to use to control the scroller location.
The other row contains all of the discussed buttons.
after wards I have created a loop to manage all the events when triggered:
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)
The buttons did not act according to the plan and when triggered a warning jumped up:
Warning setting the vertical scroll (yview_moveto failed) 'TkScrollableFrame' object has no attribute 'yview_moveto
It seems like I did everything according to the documentation of pysimplegui but it doesn't work. Any help will be appreciated.
thanks, with respect, revolution.
Operating system: Windows 10 Python version: 3.8.1
Upvotes: 1
Views: 3527
Reputation: 169
After contacting pysimplegui and other contributors via github the explanation for the warnings was the following:
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.
more over a solution was offered in the form of tkinter calls and 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()
Upvotes: 1