如何将密码添加到选项卡以打开其内容



Dears,

如何向选项卡添加密码以打开其内容?

我想让Tab1(手机)和Tab3(电脑)保持可访问性,每次我们点击它们时,其他的都会请求密码:

下面是我的布局的代码,它有4个选项卡,其中2个是打开的:

import PySimpleGUI as sg
accessible = ['Mobiles','Computers']
layout = [[sg.TabGroup([[
sg.Tab('Mobiles', [[sg.Text(f'This is the Tab 1')]],key='Mobiles'), 
sg.Tab('Tabelettes', [[sg.Text(f'This is the 
Tab2')]],key='Tabelettes'),
sg.Tab('Computers',[[sg.Text(f'This is the 
Tab3')]],key='Computers'),
sg.Tab('Televisions',[[sg.Text(f'This is the 
Tab4')]],key='Televisions')]],selected_title_color='yellow', 
key='TabGroup')]]
window = sg.Window('Tab Group', layout, finalize=True)
window['TabGroup'].bind('<Button-1>', ' Change', propagate=False)
while True:
event, values = window.read()
if event == sg.WIN_CLOSED:
break
elif event == 'TabGroup Change':
e = window['TabGroup'].user_bind_event
if e.widget.identify(e.x, e.y) == 'label':
index = e.widget.index(f'@{e.x},{e.y}')
if index in accessible:
window[f'Tab {index}'].select()
else:
if sg.popup_get_text("Password") == '2022':
window[f'Tab {index}'].select()
window.close()

提前感谢

只需将索引转换为tab的键即可。

import PySimpleGUI as sg
tabs = ['Mobiles', 'Tabelettes', 'Computers', 'Televisions']
accessible = {'Mobiles','Computers'}
layout = [[sg.TabGroup([[sg.Tab(tab, [[sg.Text(f'This is the Tab {i+1}')]], key=tab) for i, tab in enumerate(tabs)]], selected_title_color='yellow', key='TabGroup')]]
window = sg.Window('Tab Group', layout, finalize=True)
window['TabGroup'].bind('<Button-1>', ' Change', propagate=False)
while True:
event, values = window.read()
if event == sg.WIN_CLOSED:
break
elif event == 'TabGroup Change':
e = window['TabGroup'].user_bind_event
if e.widget.identify(e.x, e.y) == 'label':
index = e.widget.index(f'@{e.x},{e.y}')
tab = tabs[index]
if tab in accessible:
window[tab].select()
else:
if sg.popup_get_text("Password") == '2022':
accessible.add(tab)
window[tab].select()
window.close()

相关内容

最新更新