[英]PySimpleGUI : Update Window Property
我想更新 PySimpleGUI 窗口的属性no_titlebar
。
我想要的是,当我们点击一个按钮时,最初有标题栏的窗口应该没有标题栏。
有什么方法可以实现吗?
from PySimpleGUI import *
lt=[[Button("No Layout")]]
wn=Window("Test",lt,no_titlebar=False)
while True:
e,v=wn.read()
if e=="No Layout":
wn.Update(no_titlebar=True)
else:
break
我试过这个,但得到了一个 AttributeError
AttributeError: 'Window' object has no attribute 'Update'
没有Update
sg.Window
的方法,也没有更新no_titlebar
方法。
以下代码仅供参考,我对Linux一无所知,因此您可能需要自己找到window.TKroot.wm_attributes("-type", value)
来恢复工具栏的答案。
import PySimpleGUI as sg
def titlebar(state):
try:
if sg.running_linux():
if state:
window.TKroot.wm_attributes("-type", 'normal') # Don't know what the option `normal` should be ...
else:
window.TKroot.wm_attributes("-type", 'dock')
else:
if state:
window.TKroot.wm_overrideredirect(False)
else:
window.TKroot.wm_overrideredirect(True)
except Exception as e:
print(f'** Problem setting no titlebar {e} **')
layout = [
[sg.Button("Title bar On/Off"), sg.Button('Exit')],
]
window = sg.Window("Test", layout)
state = True
while True:
event, values = window.read()
if event in (sg.WINDOW_CLOSED, 'Exit'):
break
elif event == "Title bar On/Off":
state = not state
titlebar(state)
window.close()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.