Pysimplegui: [Bug] controlling the scroller via set_vscroll_position() does not work for Column elements

Created on 21 Aug 2020  路  7Comments  路  Source: PySimpleGUI/PySimpleGUI

Bug

Operating System: windows 10

Python version: 3.8.1

PySimpleGUI Port and Version:


4.28.0 Released 3-Aug-2020

Your Experience Levels In Months or Years

____2y_____ Python programming experience
____5y_____ Programming experience overall
____no_____ Have used another Python GUI Framework (tkinter, Qt, etc) previously (yes/no is fine)?

You have completed these steps:

  • [x] Read instructions on how to file an Issue
  • [x] Searched through main docs http://www.PySimpleGUI.org for your problem
  • [x] Searched through the readme for your specific port if not PySimpleGUI (Qt, WX, Remi)
  • [x] Looked for Demo Programs that are similar to your goal http://www.PySimpleGUI.com
  • [x] Note that there are also Demo Programs under each port on GitHub
  • [x] Run your program outside of your debugger (from a command line)
  • [x] Searched through Issues (open and closed) to see if already reported
  • [x] Try again by upgrading your PySimpleGUI.py file to use the current one on GitHub. Your problem may have already been fixed but is not yet on PyPI.

I'm trying to use the set_vscroll_position() in order to ease the user navigation in a column containing lots of rows full with input boxes but it keeps firing the following warnings and does not work:

Warning setting the vertical scroll (yview_moveto failed)
'TkScrollableFrame' object has no attribute 'yview_moveto'

My Code

This program is creating a window which contains a column that has a pre determined layout containing all the mentioned input boxes and a pre determined sizes.

in addition there are the discussed buttons inside.

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")]
                ])


while True:
    event, values = form.read()

    if(event == sg.WIN_CLOSED):
        break
    elif(event == "down"):
        form.Element('Column').set_vscroll_position(1.0)
    elif(event == "up"):
        form.Element('Column').set_vscroll_position(0.0)

Most helpful comment

Here's the code to show how to control the scrollbar at this moment.

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()

All 7 comments

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.

The set_scroll_position is a really simple function:

            self.Widget.yview_moveto(percent_from_top)

The vertical scrollbar is a member variable:
Widget.vscrollbar

I think you should be able to manipulate this scrollbar directly as a workaround. I haven't tried it yet but wanted to get you the info so you can see if you're able to make something work.

Thank you very much for the quick response, but i have some follow up question:

1) by "manipulate this scrollbar directly as a workaround" are you suggesting solutions that are not necessarily related to pysimplegui, such as bots or a connected program?

2) Will it be inserted to the column element later on?

3) What other element is a stand alone widget that I can use instead?

with respect,
roey-coding

It was originally added, not long ago, for the Table element

https://github.com/PySimpleGUI/PySimpleGUI/issues/1878

  1. Manipulate using tkinter calls... you'll find a number of workarounds in the Issues that use the Widget variable for example
  2. It would be good to support the column
  3. I don't know.

I will use a table but in the future i would love to get back to column so i'm keeping this issue open until columns will be supported in controlling the scrollbar, for all of the columns users out there.

In the mid time, can you please direct me to the place in your code where the columns? in order to use tkinter calls I need to know exactly what is a column and how does it look in code.

please update here when the feature is added, for the sake of all the column users out there.

with respect,
roey-coding

I'm sorry I don't have the ability to step you through adding this feature.

Here's the code to show how to control the scrollbar at this moment.

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()

Thank you very much jason990420 and PySimpleGUI for you helpful responses, hopefully it will be added in the future, keeping it open until the far future update that will make an official method but for know that will definitely do.

with respect,
revolution

Was this page helpful?
0 / 5 - 0 ratings