遵循本教程:
https://bitesofcode.blogspot.com/2011/10/nexsys-building-full-application.html
运行此代码后,窗口将打开,但是会出现错误消息,并且无法正确关闭应用程序,即退出该应用程序的唯一方法是退出终端。 以下代码恰好唯一的区别是shebang,因为我使用python3,所以请使用shebang。我已经在Qt4上工作了几周了,以前没有遇到过这个问题,但是我只是现在才知道要确保只有QApplication的一个实例在运行,等等。因此,代码中必须包含一些内容造成了问题。不幸的是,我没有找到有关display参数的任何信息。任何帮助将不胜感激。
#!/usr/bin/python3
""" Main entry point to the nexsys application. """
# define authorship information
__authors__ = ['Eric Hulser']
__author__ = ','.join(__authors__)
__credits__ = []
__copyright__ = 'Copyright (c) 2011'
__license__ = 'GPL'
# maintanence information
__maintainer__ = 'Eric Hulser'
__email__ = 'eric.hulser@gmail.com'
from PyQt4 import QtGui
def main(argv = None):
"""
Creates the main window for the nexsys application and begins the \
QApplication if necessary.
:param argv | [, ..] || None
:return error code
"""
app = None
# create the application if necessary
if ( not QtGui.QApplication.instance() ):
app = QtGui.QApplication(argv)
app.setStyle('plastique')
# create the main window
QtGui.QMessageBox.information(None, 'Stub', 'Create the Main Window!')
# run the application if necessary
if ( app ):
return app.exec_()
# no errors since we're not running our own event loop
return 0
if ( __name__ == '__main__' ):
import sys
sys.exit(main(sys.argv))