简体   繁体   English

PySimpleGUI:更新窗口属性

[英]PySimpleGUI : Update Window Property

I would like to update the property no_titlebar of a PySimpleGUI Window.我想更新 PySimpleGUI 窗口的属性no_titlebar

What I want is that, when we click a button , the window which was initially having titlebar should be having no titlebar .我想要的是,当我们点击一​​个按钮时最初有标题栏的窗口应该没有标题栏

Is there any way to Implement this ?有什么方法可以实现吗?

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

I tried this but was getting an AttributeError我试过这个,但得到了一个 AttributeError

AttributeError: 'Window' object has no attribute 'Update'

There's no method Update for sg.Window , and no method to update no_titlebar .没有Update sg.Window的方法,也没有更新no_titlebar方法。

Following code just for your reference, I know nothing about Linux, so you may need to find the answer by youself about what value for window.TKroot.wm_attributes("-type", value) to restore toolbar.以下代码仅供参考,我对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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM