PySimpleGUI : После повторного включения видимости элемента, он не встаёт на своё место
Элемент под цифрой 3 почему-то переходит на новую строку, если ему сначала отключить, а потом включить видимость... Не могу найти причину.

import PySimpleGUI as sg
def WTF_2():
window.Element("1").Update('1', visible=False)
window.Element("2").Update('2', visible=False)
window.Element("3").Update('3', visible=False)
def WTF_1():
window.Element("1").Update('1', visible=True)
window.Element("2").Update('2', visible=True)
window.Element("3").Update('3', visible=True)
layout = [
[sg.InputText("0", justification="center", key='0', size=(10, 1)),
sg.InputText("1", justification="center", key='1', size=(10, 1))
],
[
sg.InputText("2", justification="center", key='2', size=(10, 1)),
sg.InputText("3", justification="center", key='3', size=(10, 1))
],
[sg.Button('WTF_1', key='WTF_1'), sg.Button('WTF_2', key='WTF_2')]
]
window = sg.Window('000', layout)
while True:
event, values = window.read(timeout=1)
if event == 'Exit' or event == 'Cancel' or event == 'Отмена' or event == sg.WIN_CLOSED:
print('Good Bye!')
window.close()
break
elif event == "WTF_1":
WTF_1()
elif event == "WTF_2":
WTF_2()
Проблема пропадает, если оставить нижний элемент неизменяемым, но можно ли как-то без этого обойтись?
Ответы (2 шт):
Автор решения: user405186
→ Ссылка
Короче, решил проблему, засунув каждый элемент в столбец.
import PySimpleGUI as sg
def WTF_2():
window.Element("1").Update('1', visible=False)
window.Element("2").Update('2', visible=False)
window.Element("3").Update('3', visible=False)
def WTF_1():
window.Element("1").Update('1', visible=True)
window.Element("2").Update('2', visible=True)
window.Element("3").Update('3', visible=True)
col1 = [[sg.InputText("0", justification="center", key='0', size=(10, 1))]]
col2 = [[sg.InputText("1", justification="center", key='1', size=(10, 1))]]
col3 = [[sg.InputText("2", justification="center", key='2', size=(10, 1))]]
col4 = [[sg.InputText("3", justification="center", key='3', size=(10, 1))]]
layout = [
[sg.Column(col1), sg.Column(col2)], [sg.Column(col3), sg.Column(col4)],
[sg.Button('WTF_1', key='WTF_1'), sg.Button('WTF_2', key='WTF_2')]
]
window = sg.Window('000', layout)
while True:
event, values = window.read(timeout=1)
if event == 'Exit' or event == 'Cancel' or event == 'Отмена' or event == sg.WIN_CLOSED:
print('Good Bye!')
window.close()
break
elif event == "WTF_1":
WTF_1()
elif event == "WTF_2":
WTF_2()
Автор решения: Womba 306
→ Ссылка
Так как ты располагаешь их так
layout = [
[sg.InputText("0", justification="center", key='0', size=(10, 1)),
sg.InputText("1", justification="center", key='1', size=(10, 1))
],
[
sg.InputText("2", justification="center", key='2', size=(10, 1)),
sg.InputText("3", justification="center", key='3', size=(10, 1))
]
он будет иногда их группировать в столбец. Лучше делать так
layout = [
[sg.InputText("0", justification="center", key='0', size=(10, 1)), sg.InputText("1", justification="center", key='1', size=(10, 1))],
[sg.InputText("2", justification="center", key='2', size=(10, 1)), sg.InputText("3", justification="center", key='3', size=(10, 1))]
]