New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ Enhancement/Question] Programmatically setting Horizontal Scroll position of a Column() #6735
Comments
Simple demo code for horizontal-position scroll. import PySimpleGUI as sg
def set_hscroll_position(self, percent_from_left):
"""
Attempts to set the horizontal scroll postition for an element's Widget
:param percent_from_left: From 0 to 1.0, the percentage from the left to move scrollbar to
:type percent_from_left: (float)
"""
if self.Type == sg.ELEM_TYPE_COLUMN and self.Scrollable:
widget = self.widget.canvas # scrollable column is a special case
else:
widget = self.widget
try:
widget.xview_moveto(percent_from_left)
except Exception as e:
print('Warning setting the horizontal scroll (xview_moveto failed)')
print(e)
sg.Element.set_hscroll_position = set_hscroll_position
sg.theme("DarkBlue")
sg.set_options(font=("Courier New", 20))
column_layout = [[sg.Input(f"({row}, {col})", size=6, pad=(0, 0), key=("-IN-", row, col)) for col in range(10)] for row in range(10)]
layout = [
[sg.Button("<"),
sg.Column(column_layout, pad=(0, 0), scrollable=True, size_subsample_width=2, size_subsample_height=2, key="-COLUMN-"),
sg.Button(">")],
]
window = sg.Window("Title", layout, finalize=True)
percent = 0
while True:
event, values = window.read()
if event == sg.WIN_CLOSED:
break
elif event == "<" and percent > 0:
percent -= 0.1
window["-COLUMN-"].set_hscroll_position(percent)
elif event == ">" and percent < 1.0:
percent += 0.1
window["-COLUMN-"].set_hscroll_position(percent)
window.close() |
WOW Will try this immediately!!! And quick question... |
And Jason... IT WORKS !!! |
Just quickly. Also, but not important... def set_hscroll_position(self, percent_from_top): Cheers! |
Regarding converting the license to COMMERCIAL, maybe just put a button "UPGRADE" on the License Page. Feel free to close this thread. Thanks again. |
Yesterday I added this feature to 5.0.4.3. Jason and I used the same name This is the docstring you'll find in the code I checked in. def set_hscroll_position(self, percent_from_left):
"""
Attempts to set the horizontal scroll postition for an element's Widget
:param percent_from_left: From 0 to 1.0, the percentage from the left to move scrollbar to
:type percent_from_left: (float)
""" This is the test harness I was using to test it: import PySimpleGUI as sg
col_layout = [[sg.Text('Column')],
[sg.Multiline(size=(150,40))],
[sg.Input(key='-IN-')],
[sg.Text('Text at the bottom')],
]
layout = [[sg.Column(col_layout, k='-COL-', scrollable=True, size=(400,400))],
[sg.VPush()],
[sg.Text('% to set scroll from left'), sg.In(k='-RIGHT-', s=4), sg.B('Scroll'), sg.Button('Exit'), sg.Sizegrip()]
]
window = sg.Window('Scroll Test', layout, resizable=True)
while True:
event, values = window.read()
print(event, values)
if event == sg.WIN_CLOSED or event == 'Exit':
break
if event == 'Scroll':
window['-COL-'].set_hscroll_position(float(values['-RIGHT-'])/100)
window.close() I forgot to come back to this issue and post that I made the change. I'm sorry about that! I got really busy. |
We are working on this. In the meantime we're writing a FAQ entry on how to go about changing the license. Thank you for the support! |
You guys ROCK !!!
👍👍👍
… On 6 Apr 2024, at 15:21, PySimpleGUI ***@***.***> wrote:
Yesterday I added this feature to 5.0.4.3. Jason and I used the same name set_hscroll_position, except that I used parameter named percent_from_left.
This is the docstring you'll find in the code I checked in.
def set_hscroll_position(self, percent_from_left):
"""
Attempts to set the horizontal scroll postition for an element's Widget
:param percent_from_left: From 0 to 1.0, the percentage from the left to move scrollbar to
:type percent_from_left: (float)
"""
—
Reply to this email directly, view it on GitHub <#6735 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/APMJEMU6N27A5QW7KRVYZ2TY36WAHAVCNFSM6AAAAABFZKKRKSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANBRGAYTINJXGU>.
You are receiving this because you authored the thread.
|
Your support and contributions are FAB Jason.
Thank you so much!
… On 6 Apr 2024, at 00:50, Jason Yang ***@***.***> wrote:
Simple demo code for horizontal-position scroll.
import PySimpleGUI as sg
def set_hscroll_position(self, percent_from_top):
"""
Attempts to set the hertical scroll postition for an element's Widget
:param percent_from_top: From 0 to 1.0, the percentage from the left to move scrollbar to
:type percent_from_top: (float)
"""
if self.Type == sg.ELEM_TYPE_COLUMN and self.Scrollable:
widget = self.widget.canvas # scrollable column is a special case
else:
widget = self.widget
try:
widget.xview_moveto(percent_from_top)
except Exception as e:
print('Warning setting the horizontal scroll (xview_moveto failed)')
print(e)
sg.Element.set_hscroll_position = set_hscroll_position
sg.theme("DarkBlue")
sg.set_options(font=("Courier New", 20))
column_layout = [[sg.Input(f"({row}, {col})", size=6, pad=(0, 0), key=("-IN-", row, col)) for col in range(10)] for row in range(10)]
layout = [
[sg.Button("<"),
sg.Column(column_layout, pad=(0, 0), scrollable=True, size_subsample_width=2, size_subsample_height=2, key="-COLUMN-"),
sg.Button(">")],
]
window = sg.Window("Title", layout, finalize=True)
percent = 0
while True:
event, values = window.read()
if event == sg.WIN_CLOSED:
break
elif event == "<" and percent > 0:
percent -= 0.1
window["-COLUMN-"].set_hscroll_position(percent)
elif event == ">" and percent < 1.0:
percent += 0.1
window["-COLUMN-"].set_hscroll_position(percent)
window.close()
image.png (view on web) <https://github.com/PySimpleGUI/PySimpleGUI/assets/55352169/de3355bf-4327-4ccc-8be8-f6b2b5a2a0e1>
—
Reply to this email directly, view it on GitHub <#6735 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/APMJEMWVMBMA65NEP2MIOE3Y33P5NAVCNFSM6AAAAABFZKKRKSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANBQGMZTEMBZGY>.
You are receiving this because you authored the thread.
|
Type of Issue (Enhancement, Question)
Programmatically setting Horizontal Scroll position of a Column
Operating System
PC Windows 11 / macOS Sonoma
PySimpleGUI Port (tkinter, Qt, Wx, Web)
tkinter
Versions
Python version: 3.12.0
Platform: PC (Windows 11) and Mac (macOS Sonoma)
Port: PySimpleGUI
tkinter version: 8.6.13
PySimpleGUI version: 4.61.0.201
Python version (3.12.0)
PySimpleGUI Version (4.61.0.201)
GUI Version (tkinter 8.6.13)
Your Experience In Months or Years (optional) :
Years Python programming experience : 10 years
Years Programming experience overall : 40 years
Have used another Python GUI Framework? (tkinter, Qt, etc) YES
Troubleshooting
These items may solve your problem. Please check those you've done by changing - [ ] to - [X]
Detailed Description
I am writing an application that uses a spreadsheet-kind-of input area.
All input cells are placed in rows and columns in a layout that is put in a SCROLLABLE COLUMN (horizontal and vertical) because the input sheet might be larger than the displayed window.
It is important to "follow" the focussed field during input and keep it visible in the scrollable column.
Vertically, this can be done programmatically by setting and controlling the vertical scroll position of the column with:
window['<scrollable_column_key>'].set_vscroll_position(percentage)
Sadly. There is no such feature to control the horizontal scrolling position of the scrollable column...
window['<scrollable_column_key>'].set_hscroll_position(percentage)
When running the code, the following error is generated:
window['<input_sheet>'].set_hscroll_position(scroll_percentage)
^^^^^^^^^^^^^^^
AttributeError: Object has no attribute 'set_hscroll_position'. Did you mean: 'set_vscroll_position'?
It is obvious that the "set_hscroll_position" attribute is not available.
But in that case, how does one keep the focussed fields in the visible part of the scrollable column?
Without being able to do that, the input becomes really awkward and unhandy to use...
Any suggestions on a workaround or on how to fix the problem?
Thanks!
The text was updated successfully, but these errors were encountered: