我创建了一个简单的屏幕,其中有一个按钮,单击该按钮时会调用另一个屏幕。你知道吗
我找了很多。但我还是做不到: **如何在我的两个布局之间切换,以便在我单击中的按钮时测试.py布局更改为计划**你知道吗
你知道吗测试.py你知道吗
from PyQt4 import QtCore, QtGui
import subprocess
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName(_fromUtf8("Form"))
Form.resize(400, 300)
self.Button = QtGui.QPushButton(Form)
self.Button.setGeometry(QtCore.QRect(50, 40, 261, 231))
self.Button.setObjectName(_fromUtf8("Button"))
self.Button.clicked.connect(self.fun)
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
Form.setWindowTitle(_translate("Form", "Form", None))
self.Button.setText(_translate("Form", "Button", None))
def fun(self):
subprocess.call(" scherm.py 1", shell=True)
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
Form = QtGui.QWidget()
ui = Ui_Form()
ui.setupUi(Form)
Form.show()
sys.exit(app.exec_())
你知道吗计划你知道吗
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_PlaatjesScherm(object):
def setupUi(self, PlaatjesScherm):
PlaatjesScherm.setObjectName(_fromUtf8("PlaatjesScherm"))
PlaatjesScherm.resize(654, 528)
self.retranslateUi(PlaatjesScherm)
QtCore.QMetaObject.connectSlotsByName(PlaatjesScherm)
def retranslateUi(self, PlaatjesScherm):
PlaatjesScherm.setWindowTitle(_translate("PlaatjesScherm", "Plaatjes", None))
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
PlaatjesScherm = QtGui.QWidget()
ui = Ui_PlaatjesScherm()
ui.setupUi(PlaatjesScherm)
PlaatjesScherm.show()
sys.exit(app.exec_())
与其使用
subprocess.call()
,我建议您将scherm
设为QDialog。这样,您就可以简单地创建类Ui_PlatjesScherm
的实例,而不是在插槽fun(self)
中运行另一个脚本。您需要为该类添加一个__init__
方法。你知道吗这就是我打开新窗口的方法:
在我的主类中,以下是创建“AddStationUI”窗口的方法:
这将创建
AddStationUI
的实例,并在__init__
方法中加载UI并执行它。这样,您就不必使用subprocess
,两个窗口将并行运行。你知道吗相关问题 更多 >
编程相关推荐