RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题 / 1600959
Accepted
Nikita
Nikita
Asked:2024-11-27 04:50:40 +0000 UTC2024-11-27 04:50:40 +0000 UTC 2024-11-27 04:50:40 +0000 UTC

窗口已创建,但无法打开

  • 772

当您在 PyQt6 中运行程序时,会创建一个窗口,但您无法打开它。

PS
该程序是从 Qt Designer 自动创建的。我只是添加了super(Ui_MainWindow, self).__init__(),但是没有它也无法打开。

from PyQt6 import QtCore, QtGui, QtWidgets


class Ui_MainWindow(object):
    def setupUi(self, MainWindow):

        super(Ui_MainWindow, self).__init__()    

        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(800, 600)
        MainWindow.setWindowOpacity(0.0)
        MainWindow.setStyleSheet("background-color: rgb(89, 89, 89);")
        MainWindow.setIconSize(QtCore.QSize(32, 32))
        self.centralwidget = QtWidgets.QWidget(parent=MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.scrollArea = QtWidgets.QScrollArea(parent=self.centralwidget)
        self.scrollArea.setGeometry(QtCore.QRect(50, 20, 161, 545))
        self.scrollArea.setWidgetResizable(True)
        self.scrollArea.setObjectName("scrollArea")
        self.scrollAreaWidgetContents = QtWidgets.QWidget()
        self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 159, 543))
        self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents")
        self.label = QtWidgets.QLabel(parent=self.scrollAreaWidgetContents)
        self.label.setGeometry(QtCore.QRect(10, 20, 141, 16))
        self.label.setStyleSheet("color: rgb(255, 255, 255);")
        self.label.setObjectName("label")
        self.label_2 = QtWidgets.QLabel(parent=self.scrollAreaWidgetContents)
        self.label_2.setGeometry(QtCore.QRect(10, 40, 141, 16))
        self.label_2.setStyleSheet("color: rgb(255, 255, 255);")
        self.label_2.setObjectName("label_2")
        self.verticalScrollBar = QtWidgets.QScrollBar(parent=self.scrollAreaWidgetContents)
        self.verticalScrollBar.setGeometry(QtCore.QRect(144, 0, 15, 482))
        self.verticalScrollBar.setMaximum(1200)
        self.verticalScrollBar.setOrientation(QtCore.Qt.Orientation.Vertical)
        self.verticalScrollBar.setObjectName("verticalScrollBar")
        self.scrollArea.setWidget(self.scrollAreaWidgetContents)
        self.Settings = QtWidgets.QToolButton(parent=self.centralwidget)
        self.Settings.setGeometry(QtCore.QRect(10, 20, 32, 32))
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap("copy_4043715.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
        self.Settings.setIcon(icon)
        self.Settings.setIconSize(QtCore.QSize(64, 64))
        self.Settings.setAutoRaise(True)
        self.Settings.setObjectName("Settings")
        self.Settings_2 = QtWidgets.QToolButton(parent=self.centralwidget)
        self.Settings_2.setGeometry(QtCore.QRect(10, 60, 32, 32))
        icon1 = QtGui.QIcon()
        icon1.addPixmap(QtGui.QPixmap("search_4232773.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
        self.Settings_2.setIcon(icon1)
        self.Settings_2.setIconSize(QtCore.QSize(64, 64))
        self.Settings_2.setAutoRaise(True)
        self.Settings_2.setObjectName("Settings_2")
        self.Settings_3 = QtWidgets.QToolButton(parent=self.centralwidget)
        self.Settings_3.setGeometry(QtCore.QRect(10, 100, 32, 32))
        icon2 = QtGui.QIcon()
        icon2.addPixmap(QtGui.QPixmap("settings_4502134.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
        self.Settings_3.setIcon(icon2)
        self.Settings_3.setIconSize(QtCore.QSize(64, 64))
        self.Settings_3.setAutoRaise(True)
        self.Settings_3.setObjectName("Settings_3")
        self.textEdit = QtWidgets.QTextEdit(parent=self.centralwidget)
        self.textEdit.setGeometry(QtCore.QRect(210, 20, 590, 540))
        font = QtGui.QFont()
        font.setFamily("Dubai")
        font.setPointSize(16)
        self.textEdit.setFont(font)
        self.textEdit.setStyleSheet("color: rgb(213, 213, 213);")
        self.textEdit.setObjectName("textEdit")
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(parent=MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 22))
        self.menubar.setObjectName("menubar")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(parent=MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "Saturn"))
        self.label.setText(_translate("MainWindow", "File1.txt"))
        self.label_2.setText(_translate("MainWindow", "File2.txt"))
        self.Settings.setText(_translate("MainWindow", "..."))
        self.Settings_2.setText(_translate("MainWindow", "..."))
        self.Settings_3.setText(_translate("MainWindow", "..."))
        self.textEdit.setHtml(_translate("MainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'Dubai\'; font-size:16pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:\'MS Shell Dlg 2\'; font-size:7.875pt;\">1232131</span></p>\n"
"<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:\'MS Shell Dlg 2\'; font-size:7.875pt;\"><br /></p></body></html>"))


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec())
python
  • 1 1 个回答
  • 34 Views

1 个回答

  • Voted
  1. Best Answer
    S. Nick
    2024-11-27T05:08:13Z2024-11-27T05:08:13Z

    永远不要更改Qt Designer生成的代码。
    创建另一个继承相应小部件的类,并使用创建的类来填充它。

    窗口不透明度:双

    该属性包含窗口的不透明度级别。
    可接受的不透明度范围是从1.0(完全不透明)到0.0(完全透明)。
    该属性的默认值为 1.0。

    '''
    from PyQt6 import QtCore, QtGui, QtWidgets
    '''
    from PyQt5 import QtCore, QtGui, QtWidgets
    
    
    class Ui_MainWindow(object):
        def setupUi(self, MainWindow):
    
    #?        super(Ui_MainWindow, self).__init__()    
    
            MainWindow.setObjectName("MainWindow")
            MainWindow.resize(800, 600)
            
    #?        MainWindow.setWindowOpacity(0.0)
    
            MainWindow.setStyleSheet("background-color: rgb(89, 89, 89);")
            MainWindow.setIconSize(QtCore.QSize(32, 32))
            self.centralwidget = QtWidgets.QWidget(parent=MainWindow)
            self.centralwidget.setObjectName("centralwidget")
            self.scrollArea = QtWidgets.QScrollArea(parent=self.centralwidget)
            self.scrollArea.setGeometry(QtCore.QRect(50, 20, 161, 545))
            self.scrollArea.setWidgetResizable(True)
            self.scrollArea.setObjectName("scrollArea")
            self.scrollAreaWidgetContents = QtWidgets.QWidget()
            self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 159, 543))
            self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents")
            self.label = QtWidgets.QLabel(parent=self.scrollAreaWidgetContents)
            self.label.setGeometry(QtCore.QRect(10, 20, 141, 16))
            self.label.setStyleSheet("color: rgb(255, 255, 255);")
            self.label.setObjectName("label")
            self.label_2 = QtWidgets.QLabel(parent=self.scrollAreaWidgetContents)
            self.label_2.setGeometry(QtCore.QRect(10, 40, 141, 16))
            self.label_2.setStyleSheet("color: rgb(255, 255, 255);")
            self.label_2.setObjectName("label_2")
            self.verticalScrollBar = QtWidgets.QScrollBar(parent=self.scrollAreaWidgetContents)
            self.verticalScrollBar.setGeometry(QtCore.QRect(144, 0, 15, 482))
            self.verticalScrollBar.setMaximum(1200)
            self.verticalScrollBar.setOrientation(QtCore.Qt.Orientation.Vertical)
            self.verticalScrollBar.setObjectName("verticalScrollBar")
            self.scrollArea.setWidget(self.scrollAreaWidgetContents)
            self.Settings = QtWidgets.QToolButton(parent=self.centralwidget)
            self.Settings.setGeometry(QtCore.QRect(10, 20, 32, 32))
            icon = QtGui.QIcon()
            icon.addPixmap(QtGui.QPixmap("copy_4043715.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
            self.Settings.setIcon(icon)
            self.Settings.setIconSize(QtCore.QSize(64, 64))
            self.Settings.setAutoRaise(True)
            self.Settings.setObjectName("Settings")
            self.Settings_2 = QtWidgets.QToolButton(parent=self.centralwidget)
            self.Settings_2.setGeometry(QtCore.QRect(10, 60, 32, 32))
            icon1 = QtGui.QIcon()
            icon1.addPixmap(QtGui.QPixmap("search_4232773.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
            self.Settings_2.setIcon(icon1)
            self.Settings_2.setIconSize(QtCore.QSize(64, 64))
            self.Settings_2.setAutoRaise(True)
            self.Settings_2.setObjectName("Settings_2")
            self.Settings_3 = QtWidgets.QToolButton(parent=self.centralwidget)
            self.Settings_3.setGeometry(QtCore.QRect(10, 100, 32, 32))
            icon2 = QtGui.QIcon()
            icon2.addPixmap(QtGui.QPixmap("settings_4502134.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
            self.Settings_3.setIcon(icon2)
            self.Settings_3.setIconSize(QtCore.QSize(64, 64))
            self.Settings_3.setAutoRaise(True)
            self.Settings_3.setObjectName("Settings_3")
            self.textEdit = QtWidgets.QTextEdit(parent=self.centralwidget)
            self.textEdit.setGeometry(QtCore.QRect(210, 20, 590, 540))
            font = QtGui.QFont()
            font.setFamily("Dubai")
            font.setPointSize(16)
            self.textEdit.setFont(font)
            self.textEdit.setStyleSheet("color: rgb(213, 213, 213);")
            self.textEdit.setObjectName("textEdit")
            MainWindow.setCentralWidget(self.centralwidget)
            self.menubar = QtWidgets.QMenuBar(parent=MainWindow)
            self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 22))
            self.menubar.setObjectName("menubar")
            MainWindow.setMenuBar(self.menubar)
            self.statusbar = QtWidgets.QStatusBar(parent=MainWindow)
            self.statusbar.setObjectName("statusbar")
            MainWindow.setStatusBar(self.statusbar)
    
            self.retranslateUi(MainWindow)
            QtCore.QMetaObject.connectSlotsByName(MainWindow)
    
        def retranslateUi(self, MainWindow):
            _translate = QtCore.QCoreApplication.translate
            MainWindow.setWindowTitle(_translate("MainWindow", "Saturn"))
            self.label.setText(_translate("MainWindow", "File1.txt"))
            self.label_2.setText(_translate("MainWindow", "File2.txt"))
            self.Settings.setText(_translate("MainWindow", "..."))
            self.Settings_2.setText(_translate("MainWindow", "..."))
            self.Settings_3.setText(_translate("MainWindow", "..."))
            self.textEdit.setHtml(_translate("MainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
    "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
    "p, li { white-space: pre-wrap; }\n"
    "</style></head><body style=\" font-family:\'Dubai\'; font-size:16pt; font-weight:400; font-style:normal;\">\n"
    "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:\'MS Shell Dlg 2\'; font-size:7.875pt;\">1232131</span></p>\n"
    "<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:\'MS Shell Dlg 2\'; font-size:7.875pt;\"><br /></p></body></html>"))
    
    
    class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
        def __init__(self):
            super().__init__()
            self.setupUi(self) 
    
            # тут ваша логика
            
    
    if __name__ == "__main__":
        import sys
        
        app = QtWidgets.QApplication(sys.argv)
        w = MainWindow()
        w.show()
        sys.exit(app.exec())
    

    在此输入图像描述

    • 2

相关问题

  • 是否可以以某种方式自定义 QTabWidget?

  • telebot.anihelper.ApiException 错误

  • Python。检查一个数字是否是 3 的幂。输出 无

  • 解析多个响应

  • 交换两个数组的元素,以便它们的新内容也反转

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5