我正在写两篇文章。在Pyqt上,我创建了一个带有一些按钮的窗口。第一个按钮是小鸡并运行我的.py代码。我的意思是,当我运行我的pyqt并点击我的第一个按钮时,我想运行file1.py。
我看到了一些类似的问题,但我可以用这些信息来做。
我有这个错误:Form object has no attribute aaa
file1.py
def main():
auto = 5
print(auto)
if __name__ == '__main__':
main()
我的Pyqt代码是:
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4 import QtGui, QtCore
import file1
class Form(QDialog):
def __init__(self, parent=None):
super(Form, self).__init__(parent)
layout = QVBoxLayout()
#Marketplace
self.b1 = QPushButton("Market Places")
self.b1.setCheckable(True)
self.b1.clicked.connect(lambda:self.whichbtn(self.b1))
self.b1.clicked.connect(self.btnstate)
layout.addWidget(self.b1)
self.setLayout(layout)
#Inventory
self.b2 = QPushButton("Inventory Sources")
self.b2.setCheckable(True)
self.b2.clicked.connect(lambda:self.whichbtn(self.b2))
self.b2.clicked.connect(self.btnstate)
self.b2.clicked.connect(self.aaa)
def aaa (self):
file1()
layout.addWidget(self.b2)
self.setLayout(layout)
#Exit
self.b4 = QPushButton("EXIT")
self.b4.setDefault(True)
self.b4.clicked.connect(lambda:self.whichbtn(self.b4))
layout.addWidget(self.b4)
self.b4.clicked.connect(QtCore.QCoreApplication.instance().quit)
self.setGeometry(300, 300, 250, 150)
self.setWindowTitle("AOL Optimizations")
def btnstate(self):
if self.b1.isChecked():
print "button pressed"
else:
print "button released"
def whichbtn(self,b):
print "clicked button "+b.text()
def main():
app = QApplication(sys.argv)
ex = Form()
ex.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()`