Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python在尝试切换Python中的qt屏幕时崩溃_Python_Python 3.x_Pyqt_Pyqt5 - Fatal编程技术网

Python在尝试切换Python中的qt屏幕时崩溃

Python在尝试切换Python中的qt屏幕时崩溃,python,python-3.x,pyqt,pyqt5,Python,Python 3.x,Pyqt,Pyqt5,正如我在《关于我》一书中所述,我目前正在为荷兰埃克斯卢的“德莱沃”游泳池数据库开发一个接口 嗯,我试图让这个人能够切换屏幕(用一个按钮,比如“返回主菜单”) 但当我连接代码并按下按钮时,屏幕上显示:Python崩溃(荷兰语) ... 有人发现错误了吗 这是我的密码: MainWindow.py: # -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'MainWindow.ui' # # Cre

正如我在《关于我》一书中所述,我目前正在为荷兰埃克斯卢的“德莱沃”游泳池数据库开发一个接口

嗯,我试图让这个人能够切换屏幕(用一个按钮,比如“返回主菜单”)

但当我连接代码并按下按钮时,屏幕上显示:Python崩溃(荷兰语) ... 有人发现错误了吗

这是我的密码:

MainWindow.py:

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'MainWindow.ui'
#
# Created by: PyQt5 UI code generator 5.5.1
#
# WARNING! All changes made in this file will be lost!

from PyQt5 import QtCore, QtGui, QtWidgets
import sys
import mysql.connector as mariadb
import ButtonFunctions

global mariadb_connection
global cursor
mariadb_connection = mariadb.connect(user='root', password='root', database='leewaldb')
cursor = mariadb_connection.cursor()

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(407, 394)
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap("media/Icon.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        MainWindow.setWindowIcon(icon)
        MainWindow.setStyleSheet("background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(9, 41, 4, 255), stop:0.085 rgba(2, 79, 0, 255), stop:0.19 rgba(50, 147, 22, 255), stop:0.275 rgba(236, 191, 49, 255), stop:0.39 rgba(243, 61, 34, 255), stop:0.555 rgba(135, 81, 60, 255), stop:0.667 rgba(121, 75, 255, 255), stop:0.825 rgba(164, 255, 244, 255), stop:0.885 rgba(104, 222, 71, 255), stop:1 rgba(93, 128, 0, 255));")
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.gridLayout_2 = QtWidgets.QGridLayout(self.centralwidget)
        self.gridLayout_2.setObjectName("gridLayout_2")
        self.gridLayout = QtWidgets.QGridLayout()
        self.gridLayout.setObjectName("gridLayout")
        self.CopyRightLabel = QtWidgets.QLabel(self.centralwidget)
        self.CopyRightLabel.setObjectName("CopyRightLabel")
        self.gridLayout.addWidget(self.CopyRightLabel, 1, 0, 1, 1)
        self.ExitButton = QtWidgets.QCommandLinkButton(self.centralwidget)
        self.ExitButton.setObjectName("ExitButton")
        self.gridLayout.addWidget(self.ExitButton, 2, 0, 1, 1)
        self.ShowEverythingButton = QtWidgets.QCommandLinkButton(self.centralwidget)
        self.ShowEverythingButton.setObjectName("ShowEverythingButton")
        self.gridLayout.addWidget(self.ShowEverythingButton, 4, 0, 1, 1)
        self.DeletePersonButton = QtWidgets.QCommandLinkButton(self.centralwidget)
        self.DeletePersonButton.setStyleSheet("")
        self.DeletePersonButton.setObjectName("DeletePersonButton")
        self.gridLayout.addWidget(self.DeletePersonButton, 7, 0, 1, 1)
        self.WelcomeLabel = QtWidgets.QLabel(self.centralwidget)
        self.WelcomeLabel.setObjectName("WelcomeLabel")
        self.gridLayout.addWidget(self.WelcomeLabel, 0, 0, 1, 1)
        self.AddPersonButton = QtWidgets.QCommandLinkButton(self.centralwidget)
        self.AddPersonButton.setObjectName("AddPersonButton")
        self.gridLayout.addWidget(self.AddPersonButton, 6, 0, 1, 1)
        self.SearchSpecificButton = QtWidgets.QCommandLinkButton(self.centralwidget)
        self.SearchSpecificButton.setObjectName("SearchSpecificButton")
        self.gridLayout.addWidget(self.SearchSpecificButton, 5, 0, 1, 1)
        self.gridLayout_2.addLayout(self.gridLayout, 0, 0, 1, 1)
        MainWindow.setCentralWidget(self.centralwidget)

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

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "BezoekersDatabase Leewal Hoofdmenu"))
        self.CopyRightLabel.setText(_translate("MainWindow", "© N.S. Geldorp & H. Nahumury 2017"))
        self.ExitButton.setText(_translate("MainWindow", "Exit"))
        self.ShowEverythingButton.setText(_translate("MainWindow", "Iedereen geregistreerd in deze database"))
        self.DeletePersonButton.setText(_translate("MainWindow", "Verwijder iemand uit de database"))
        self.WelcomeLabel.setText(_translate("MainWindow", "Welkom bij de bezoekersdatabase voor het zwembad \"De Leewal\" te Exloo"))
        self.AddPersonButton.setText(_translate("MainWindow", "Voeg iemand toe aan de database"))
        self.SearchSpecificButton.setText(_translate("MainWindow", "Zoek een specifiek persoon"))
        self.ExitButton.clicked.connect(ButtonFunctions.MainWindow.ButtonExitPressed)
        self.ShowEverythingButton.clicked.connect(ButtonFunctions.MainWindow.ButtonShowEverythingPressed)
        self.DeletePersonButton.clicked.connect(ButtonFunctions.MainWindow.ButtonDeletePersonPressed)
        self.AddPersonButton.clicked.connect(ButtonFunctions.MainWindow.ButtonAddPersonPressed)
        self.SearchSpecificButton.clicked.connect(ButtonFunctions.MainWindow.ButtonSearchSpecificPressed)

def mainforbuttonfunctions():
    app = QtWidgets.QApplication(sys.argv)
    ex = TheMainWindow.Ui_MainWindow()
    w = QtWidgets.QMainWindow()
    ex.setupUi(w)
    w.show()
    sys.exit(app.exec_())    

def main():
    app = QtWidgets.QApplication(sys.argv)
    ex = Ui_MainWindow()
    w = QtWidgets.QMainWindow()
    ex.setupUi(w)
    w.show()
    sys.exit(app.exec_())

if __name__ == "__main__":
    main()
ButtonFunctions.py:

import mysql.connector as mariadb
import MainWindow as TheMainWindow
import sys

global mariadb_connection
global cursor
mariadb_connection = mariadb.connect(user='root', password='root', database='leewaldb')
cursor = mariadb_connection.cursor()

class MainWindow():
    def ButtonExitPressed():
        cursor.execute("shutdown")
        exit()

    def ButtonShowEverythingPressed():
        pass

    def ButtonDeletePersonPressed():
        pass

    def ButtonAddPersonPressed():
        pass

    def ButtonSearchSpecificPressed():
        pass

class ShowEveryone():
    def ButtonBackToMainMenuPressed():
        self.close
        TheMainWindow.mainforbuttonfunctions()
ShowEveryone.py:

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'ShowEveryone.ui'
#
# Created by: PyQt5 UI code generator 5.5.1
#
# WARNING! All changes made in this file will be lost!

from PyQt5 import QtCore, QtGui, QtWidgets
import sys
import ButtonFunctions
import MainWindow as TheMainWindow

class Ui_ShowEveryoneInDatabase(object):
    def setupUi(self, ShowEveryoneInDatabase):
        ShowEveryoneInDatabase.setObjectName("ShowEveryoneInDatabase")
        ShowEveryoneInDatabase.resize(409, 396)
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap("media/Icon.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        ShowEveryoneInDatabase.setWindowIcon(icon)
        ShowEveryoneInDatabase.setStyleSheet("background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(9, 41, 4, 255), stop:0.085 rgba(2, 79, 0, 255), stop:0.19 rgba(50, 147, 22, 255), stop:0.275 rgba(236, 191, 49, 255), stop:0.39 rgba(243, 61, 34, 255), stop:0.555 rgba(135, 81, 60, 255), stop:0.667 rgba(121, 75, 255, 255), stop:0.825 rgba(164, 255, 244, 255), stop:0.885 rgba(104, 222, 71, 255), stop:1 rgba(93, 128, 0, 255));")
        self.centralwidget = QtWidgets.QWidget(ShowEveryoneInDatabase)
        self.centralwidget.setObjectName("centralwidget")
        self.gridLayout_2 = QtWidgets.QGridLayout(self.centralwidget)
        self.gridLayout_2.setObjectName("gridLayout_2")
        self.LijstWidget = QtWidgets.QListWidget(self.centralwidget)
        self.LijstWidget.setStyleSheet("color: rgb(0, 0, 0);")
        self.LijstWidget.setObjectName("LijstWidget")
        self.gridLayout_2.addWidget(self.LijstWidget, 1, 0, 1, 1)
        self.ReturnToMainMenuButton = QtWidgets.QCommandLinkButton(self.centralwidget)
        self.ReturnToMainMenuButton.setObjectName("ReturnToMainMenuButton")
        self.gridLayout_2.addWidget(self.ReturnToMainMenuButton, 2, 0, 1, 1)
        self.gridLayout = QtWidgets.QGridLayout()
        self.gridLayout.setObjectName("gridLayout")
        self.IedereenInDatabaseLabel = QtWidgets.QLabel(self.centralwidget)
        self.IedereenInDatabaseLabel.setObjectName("IedereenInDatabaseLabel")
        self.gridLayout.addWidget(self.IedereenInDatabaseLabel, 0, 0, 1, 1)
        self.gridLayout_2.addLayout(self.gridLayout, 0, 0, 1, 1)
        ShowEveryoneInDatabase.setCentralWidget(self.centralwidget)

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

    def retranslateUi(self, ShowEveryoneInDatabase):
        _translate = QtCore.QCoreApplication.translate
        ShowEveryoneInDatabase.setWindowTitle(_translate("ShowEveryoneInDatabase", "ToonIedereen - Leewal Database"))
        self.ReturnToMainMenuButton.setText(_translate("ShowEveryoneInDatabase", "Terug naar het hoofdmenu"))
        self.IedereenInDatabaseLabel.setText(_translate("ShowEveryoneInDatabase", "Iedereen in de database:"))
        self.ReturnToMainMenuButton.clicked.connect(ButtonFunctions.ShowEveryone.ButtonBackToMainMenuPressed)

def main():
    app = QtWidgets.QApplication(sys.argv)
    ex = Ui_ShowEveryoneInDatabase()
    w = QtWidgets.QMainWindow()
    ex.setupUi(w)
    w.show()
    sys.exit(app.exec_())

if __name__ == "__main__":
    main()
提前谢谢

-纳坦


另外,如果你投了反对票,请留下一个理由,如果我修正了它或证明离开它是不公平的,请准备删除它。

你的代码非常混乱。下面是重写的
ShowEveryone.py
。这是这个示例所需的唯一文件(看起来其他文件都是以前的尝试)

除了重组之外,崩溃的根本原因是您的插槽:

class ShowEveryone():
    def ButtonBackToMainMenuPressed():
        self.close
没有“ShowEveryone”类的实例。另一个问题是您的成员方法
按钮backtomainmenuppressed
没有
self
参数。最后,您需要包含括号来调用
self.close()

顺便说一句,如果Python崩溃,请包括回溯,例如

python.exe ShowEveryone.py
  File "ShowEveryone.py", line 9
    from PyQt5 import QtCore, QtGui, QtWidgets
    ^
IndentationError: unexpected indent

它实际上崩溃了。你在哪个站台?这是生成的代码,不是吗?您有多个文件调用app.exec_389;()。这是Qt事件循环,应该只调用一次。您还可以通过一个似乎不正确的静态变量登录数据库。什么是切入点?启动程序时首先调用哪个函数?@PaulRooney我在windows上,它是使用插入pyqt模块的QtDesigner和ui/py转换器生成的。@DavidChing这是正确的方法,这是MariaDB文档中规定的方法。您正在执行main()吗从
ShowEveryone.py
main window.py
?太好了!非常感谢。没有回溯,只是出现了一个windows屏幕的东西,上面写着“Python崩溃了”。有点像,祝你好运,希望你失败。好吧,这就是我如何停止这个屏幕,但我如何打开MainWindow.py屏幕?很高兴它解开了你!我在MacOS上从PyCharm运行应用程序时看到了Windows屏幕上的东西。这是因为你需要编辑PyCharm的断点“任何异常”以挂起,这样stacktrace就会被转储。我认为你需要从头开始,因为你有MainWindow和ShowEveryone,但你说你是从ShowEveryone启动应用的,这意味着MainWindow不存在。如果您从主窗口启动应用程序,并且以某种方式将ShowEveryone显示为弹出窗口,则情况会有所不同。然后,当您单击“上一步”时,ShowEveryone将自动关闭,主窗口将成为应用程序中的活动窗口。但是你的MainWindow.py太乱了,它无法打开ShowEveryone窗口。
python.exe ShowEveryone.py
  File "ShowEveryone.py", line 9
    from PyQt5 import QtCore, QtGui, QtWidgets
    ^
IndentationError: unexpected indent