PySimpleGUI 和 PySimpleGUIQt 中的菜单行为

Menu behaviour in PySimpleGUI and PySimpleGUIQt

我是 PySimpleGUI 的新手,但我非常喜欢它。到目前为止,我开发的简单 GUI 可以很好地与 PySimpleGUI 和 PySimpleGUIQt 配合使用。但是今天我碰到了一些不能无缝转换的东西。这是一个非常简单的菜单:

import PySimpleGUI as sg
...
    sg.theme('LightGreen5')
    menu_def = [['&File', ['&Open', 'C&lose'],]]

    layout = [[sg.Menu(menu_def, background_color=('white'), text_color=('black'), \
              font=('Arial'))], \ ...

这不适用于 PySimpleGUIQt。它抱怨 background_colortext colours,以及 font 选项。但是如果我删除这些选项,只留下

    layout = [[sg.Menu(menu_def)], \ ...

它确实有效,但会产生相当俗气、无味的菜单。

我更喜欢 Qt 而不是 tkinter(或者当没有导入和使用 PySimpleGUIQt 时使用的任何东西)但是不知道如何使用 Qt and由 tkinter 生成的菜单(或其他,等等)。我是否必须创建两个不同的版本,一个用于 Qt,另一个用于 [whatever]?有什么建议么?谢谢。

PySimpleGUIQt 只是一个用户 Alpha,所以 sg.Menu 中没有选项 text_colorfont

这是为 sg.Menu 提供颜色和字体的解决方法。

import PySimpleGUIQt as sg

def menu_options(menu):

    style = """
        QMenuBar {
            background-color : white;
        }
        QMenuBar::item {
            spacing: 0px;
            padding: 2px 10px;
            background-color: white;
            color: black;
        }
        QMenuBar::item:selected {
            color: white;
            background-color: red;
        }
        QMenuBar::item:pressed {
            color: white;
            background: blue;
        }
        QMenu {
            color: black;
            background-color: white;
            border: 1px solid black;
            margin: 2px;
        }
        QMenu::item {
            background-color: transparent;
        }
        QMenu::item:selected {
            background-color: blue;
            color: white;
        }
    """

    menu = menu.Widget
    menu.setStyleSheet(style)

    font = sg.QFont('Courier New', 16, sg.QFont.Bold, True) # Family, size, bold, italic
    font.setUnderline(True)
    font.setStrikeOut(True)
    menu.setFont(font)
    for submenu in menu.findChildren(sg.QMenu):
        submenu.setFont(font)

sg.theme('LightGreen5')
menu_def = [
    ['&File', ['&Open', 'C&lose'],],
    ['&Edit', ['&Copy', '&Paste'],],
]
layout = [
    [sg.Menu(menu_def, key='-MENU-')],
    [sg.Text("Hello World", font=('Arial', 24))],
]
window = sg.Window('Title', layout, finalize=True)
menu_options(window['-MENU-'])

window.read()
window.close()