【问题标题】:PySimpleGUI : Update Window PropertyPySimpleGUI:更新窗口属性
【发布时间】:2021-10-27 07:53:04
【问题描述】:

我想更新 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'

【问题讨论】:

  • 是的,你得到了答案'Window' object has no attribute 'Update'

标签: python pysimplegui


【解决方案1】:

sg.Window 没有方法Update,也没有更新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()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-19
    • 1970-01-01
    • 1970-01-01
    • 2022-11-11
    • 1970-01-01
    • 2021-06-13
    • 1970-01-01
    • 2023-03-10
    相关资源
    最近更新 更多