Python PySide2-主窗口不显示并显示;“窗口没有响应”;
我在pyside2上有点问题。。。在我得到回应之前,但我现在不能。。我不知道为什么 下面是一些代码: main.pyPython PySide2-主窗口不显示并显示;“窗口没有响应”;,python,python-3.x,pyside2,Python,Python 3.x,Pyside2,我在pyside2上有点问题。。。在我得到回应之前,但我现在不能。。我不知道为什么 下面是一些代码: main.py app = c.QApplication(c.sys.argv) splash_pix = c.QPixmap("animation.gif") splash = c.SplashScreen("animation.gif", c.Qt.WindowStaysOnTopHint) splash.show()
app = c.QApplication(c.sys.argv)
splash_pix = c.QPixmap("animation.gif")
splash = c.SplashScreen("animation.gif", c.Qt.WindowStaysOnTopHint)
splash.show()
app.processEvents()
screen = app.primaryScreen()
size = screen.size()
main_window = c.Main(x=(size.width() // 2) - (500 // 2), y=(size.height() // 2) - (500 // 2))
splash.finish(main_window)
c.time.sleep(0.01)
main_window.show()
c.sys.exit(app.exec_())
我进口了包裹
“Main”是我制作的一个类
class Main(QWidget):
def __init__(self, x, y, width=500, height=500, parent=None):
super().__init__()
self.x, self.y, self.width, self.height = x, y, width, height
self.setStyleSheet("background-color: rgba(255, 255, 255, 1);")
self.setWindowTitle("Test")
self.setGeometry(self.x, self.y, self.width, self.height)
self.addWidgets()
def addWidgets(self):
self.welcome_label = QLabel("Test")
self.welcome_label.setStyleSheet("QLabel {qproperty-alignment: AlignCenter; font-size: 30px; font-weight: 600;}")
self.register_button = QPushButton("Register")
self.register_button.setStyleSheet("QPushButton {background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0.273, stop: 0 rgba(85,172,238,1), stop: 1 rgba(79, 165, 240, 1)); border-radius: 20px; color: white; font: bold 18px; min-width: 5em; min-height: 1.8em; padding: 1px;} QPushButton:hover {background-color: rgba(69, 131, 186, 1);}")
self.register_button.clicked.connect(self.on_register)
self.login_button = QPushButton("Login")
self.login_button.setStyleSheet("QPushButton {background-color: qlineargradient(x1:0, y1:0, x2:1, y2:0.273, stop:0 rgba(85,172,238,1), stop:1 rgba(79, 165, 240, 1)); border-radius: 20px; color: white; font: bold 18px; min-width: 5em; min-height: 1.8em; padding: 1px;} QPushButton:hover {background-color: rgba(69, 131, 186, 1);}")
self.login_button.clicked.connect(self.on_login)
self.layout = QVBoxLayout()
self.layout.addWidget(self.welcome_label)
self.layout.addWidget(self.register_button)
self.layout.addWidget(self.login_button)
self.setLayout(self.layout)
好吧,没关系,我找到了答案。。。大苏尔显然把PyQT搞砸了。 在此处修复: 在运行程序之前,基本上运行
export QT\u MAC\u WANTS\u LAYER=1
。
如此奇怪的错误..我在MacOS 11.0.1 Big Sur和PySide2 5.15.1和5.15.2上遇到了同样的问题(互联网上提到PyQt 5.15.2已经修复,但PySide2显然不是这样)。我确认QT_MAC_想要_层的解决方案,我是这样做的:
import os
os.environ['QT_MAC_WANTS_LAYER'] = '1'
什么是
c
,你为什么这样使用它?什么是飞溅屏幕?另外,Main
类缺少登录时的和注册时的方法。请仔细阅读好的问题,并始终确保您提供(可复制意味着我们甚至可以复制/粘贴您的代码并运行它,可能需要进一步修改。c是类的导入,SplashScreen是c中的一个方法。我刚刚检查过,我的代码没有问题。我尝试使用一个示例;也没有显示窗口。一定是安装错误吗?或者其他什么…我正在使用cv2和pyside2疗法。。