我可以根据pysimplegui中的用户操作使特定的行可见
我正在使用Pysimplegui创建一个基本的待办事项计划。我只想在用户运行程序时仅显示第一行。我写了接下来的4行,但已将可见性设置为false。当用户单击“添加任务”时,我希望下一行出现。如果再次单击,我希望第三行出现,这应该适用于所有行。有办法这样做吗?
这是到目前为止的代码:
import datetime
#Formatting date and time
x = datetime.datetime.now()
y = x.strftime("%x")
z = x.strftime("%A")
i = 0
def add_line():
i += 1
prac1 = [
[sg.Text(f"Welcome to the To-Do-List for {z}, {y}")],
[sg.Text('1.'),sg.InputText('',key = 'line1'),sg.Checkbox('',key='c1',visible = False)],
[sg.Text('2.', visible = False),sg.InputText('',key = 'line2', visible = False),sg.Checkbox('',key='c2',visible = False)],
[sg.Text('3.', visible = False),sg.InputText('',key = 'line3', visible = False),sg.Checkbox('',key='c3',visible = False)],
[sg.Text('4.', visible = False),sg.InputText('',key = 'line4', visible = False),sg.Checkbox('',key='c4',visible = False)],
[sg.Text('5.', visible = False),sg.InputText('',key = 'line5', visible = False),sg.Checkbox('',key='c5',visible = False)],
[sg.Button('+ Add task')],
[sg.Button('Save'), sg.Button('Exit')]
]
prac2 = [
[sg.Text('world')],
[sg.Submit()]]
layout = [
[sg.Column(prac1),
sg.VSeparator(),
sg.Column(prac2)]]
window = sg.Window('To-Do-List',layout)
while True:
event, values = window.read()
if event == sg.WIN_CLOSED or event == 'Exit':
break
elif event == '+ Add task':
"""How can i use sg.window[].update here to make lines apear sequentially?"""```
I am creating a basic to-do-list program using PySimpleGUI. I want only the first line to be shown when the user runs the program. I have written the next 4 lines, but have set the visibility to False. When user clicks 'Add Task', I want the next line to appear. If clicked again, I want the third line to appear and this should work for all lines. Is there a way to do this?
Here is the code so far:
import datetime
#Formatting date and time
x = datetime.datetime.now()
y = x.strftime("%x")
z = x.strftime("%A")
i = 0
def add_line():
i += 1
prac1 = [
[sg.Text(f"Welcome to the To-Do-List for {z}, {y}")],
[sg.Text('1.'),sg.InputText('',key = 'line1'),sg.Checkbox('',key='c1',visible = False)],
[sg.Text('2.', visible = False),sg.InputText('',key = 'line2', visible = False),sg.Checkbox('',key='c2',visible = False)],
[sg.Text('3.', visible = False),sg.InputText('',key = 'line3', visible = False),sg.Checkbox('',key='c3',visible = False)],
[sg.Text('4.', visible = False),sg.InputText('',key = 'line4', visible = False),sg.Checkbox('',key='c4',visible = False)],
[sg.Text('5.', visible = False),sg.InputText('',key = 'line5', visible = False),sg.Checkbox('',key='c5',visible = False)],
[sg.Button('+ Add task')],
[sg.Button('Save'), sg.Button('Exit')]
]
prac2 = [
[sg.Text('world')],
[sg.Submit()]]
layout = [
[sg.Column(prac1),
sg.VSeparator(),
sg.Column(prac2)]]
window = sg.Window('To-Do-List',layout)
while True:
event, values = window.read()
if event == sg.WIN_CLOSED or event == 'Exit':
break
elif event == '+ Add task':
"""How can i use sg.window[].update here to make lines apear sequentially?"""```
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要将全行可见设置或不可见,请更好地使用该行中的所有布局(例如列元素),例如列元素。只需设置指定列元素的可见可见的选项即可设置它。
另一种方法是调用窗口的方法
extend_layout
,将新行添加到本窗口内部的现有容器元素中。To set full row visible or not, better use a container, like Column element, for all the layout in that row. Just set option
visible
of specified Column element to set it visible or not.another way is to call method
extend_layout
of window to add new rows to an existing container element inside of this window.