I want to download 3 lists from 3 websites, then populate the layout (text) with that, but I'm getting trouble update, no problem downloading the lists.
import PySimpleGUI as sg
list_a, list_b, list_c = [], [], []
left_menu = [
[sg.Button("site_a")],
[sg.Button("site_b")],
[sg.Button("site_c")]
]
right_menu = []
layout = [
[
sg.Column(left_menu),
sg.VSeperator(),
sg.Column(right_menu)
]
]
if __name__ == '__main__':
window = sg.Window("Events", layout=layout)
while True:
event, values = window.read()
if event == "site_a":
list_a = download_from_site_a()
#list_a = [dict(x=1, z=4, y=0), dict(x=36, z=7, y=2)]
for a in list_a:
right_menu += [[sg.Text(f"{a}", key="-A-")]]
window["-A-"].update(a)
window.Refresh()
if event == "site_b":
pass
if event == "site_c":
pass
window.close()
At this moment, there's only one method provided to expand the layout of a container by rows, sg.Window.extend_layout
.
Demo code
from random import randint
import PySimpleGUI as sg
left_menu = [
[sg.Button("site_a")],
[sg.Button("site_b")],
[sg.Button("site_c")],
]
right_menu = []
layout = [
[sg.Column(left_menu),
sg.VSeperator(),
sg.Column(right_menu, expand_x=True, expand_y=True,
scrollable=True, vertical_scroll_only=True, key='right'),
],
]
window = sg.Window("Events", size=(640, 480), layout=layout)
while True:
event, values = window.read()
if event == sg.WINDOW_CLOSED:
break
elif event == "site_a":
items = [dict(x=randint(0, 99), z=randint(0, 99), y=randint(0, 99)) for i in range(50)]
new_rows = [[sg.Text(f"{item}", key=("-A-", i))] for i, item in enumerate(items)]
window.extend_layout(window['right'], new_rows)
window.refresh()
window['right'].contents_changed() # Update the content of `sg.Column` after window.refresh()
window.close()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.