使用 Form() 时如何更改 Python 中的主窗口标题?

How do I change the MainWindow Title in Python when using Form()?

我正在尝试更改 window 应用程序的标题,但我不知道如何针对我正在加载 *.ui 文件作为表单的特定情况。

到目前为止,我的代码的简化版本如下所示:

import sys, os
from sys import stdout, stdin, stderr
from PySide2.QtUiTools import QUiLoader
from PySide2.QtWidgets import QApplication, QPushButton, QLineEdit, QTextBrowser
from PySide2.QtCore import QFile, QObject, QEvent 

class Form(QObject):

    def __init__(self, ui_file, parent=None):
        super(Form, self).__init__(parent)
        ui_file = QFile(ui_file)
        ui_file.open(QFile.ReadOnly)

        loader = QUiLoader()
        self.window = loader.load(ui_file)
        ui_file.close()

        self.window.show()


if __name__ == '__main__':
        print("Starting up tool application...\nPlease wait.")
        app = QApplication(sys.argv)
        form = Form('mifareclassictool.ui')
        sys.exit(app.exec_())

我在 Form class 中尝试了 self.setWindowTitle("title") 但 属性 不存在。我对 Qt Designer 和在 python.

中创建应用程序还很陌生

表格不是window所以你不能使用self.setWindowTitle("title"),你应该使用self.window:

self.window.setWindowTitle("title")