【发布时间】:2018-08-17 08:16:36
【问题描述】:
大家好,我有一个问题,我必须编写 python 脚本,该脚本将首先显示一个带有按钮文本编辑和一些标签的 qt4 窗口。 我已经链接了按钮,但是当我单击脚本结尾的左侧按钮时,它会显示:
Traceback(最近一次调用最后一次): 文件“Skrypt.py”,第 18 行,位于 Koniec QtGui.QMessageBox.Yes | QtGui.QMessageBox.No) TypeError:参数不匹配任何重载调用: 问题(QWidget,str,str,按钮:Union[QMessageBox.StandardButtons,QMessageBox.StandardButton] = QMessageBox.Ok,defaultButton:QMessageBox.StandardButton = QMessageBox.NoButton):参数 1 具有意外类型 'bool' 问题(QWidget,str,str,int,button1:int = 0,button2:int = 0):参数 1 具有意外类型“bool” 问题(QWidget,str,str,str,button1Text:str = '',button2Text:str = '',defaultButtonNumber:int = 0,escapeButtonNumber:int = -1):参数 1 具有意外类型 'bool'
当我点击右边时,这将是一个 pylab 脚本,它将从中获取价值 文本编辑它显示这个:
文件“Skrypt.py”,第 26 行,位于 Zatwierdz
a = int(uiplot.textEdit())
TypeError: 'QTextEdit' 对象不可调用
我不知道如何解决这个问题,因为这是我第一次使用 qt4,所以如果有人可以帮助我,我将不胜感激
这是脚本中的代码,它将使用 matplotlib 显示函数
import skrypt1
import pylab
import skrypt1
from pylab import *
import sys
from PyQt4 import QtGui, QtCore
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
def Koniec(self):
global wybor
wybor = QtGui.QMessageBox.question(self, 'Koniec',
"Na Pewno chcesz wyjsc ?",
QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)
if wybor == QtGui.QMessageBox.Yes:
sys.exit()
else:
pass
def Zatwierdz(self):
x = pylab.arange(-10, 10.5, 0.5)
a = int(uiplot.textEdit())
y1 = [i / -3 + a for i in x if i <= 0]
y2 = [i**2 / 3 for i in x if i >= 0]
x1 = [i for i in x if i <= 0]
x2 = [i for i in x if i >= 0]
pylab.plot(x1, y1, x2, y2)
pylab.title('Wykres f(x)')
pylab.grid(True)
pylab.show()
gui_plot = skrypt1.QtGui.QMainWindow()
uiplot = skrypt1.Ui_MainWindow()
uiplot.setupUi(gui_plot)
uiplot.Zatwierdz.clicked.connect(Zatwierdz)
uiplot.Wyjscie.clicked.connect(Koniec)
gui_plot.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_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.resize(800, 600)
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
self.label = QtGui.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(50, 60, 361, 21))
self.label.setObjectName(_fromUtf8("label"))
self.label_2 = QtGui.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(50, 270, 361, 21))
self.label_2.setObjectName(_fromUtf8("label_2"))
self.textEdit = QtGui.QTextEdit(self.centralwidget)
self.textEdit.setGeometry(QtCore.QRect(40, 360, 711, 71))
self.textEdit.setObjectName(_fromUtf8("textEdit"))
self.Zatwierdz = QtGui.QPushButton(self.centralwidget)
self.Zatwierdz.setGeometry(QtCore.QRect(560, 500, 200, 28))
self.Zatwierdz.setObjectName(_fromUtf8("Zatwierdz"))
self.Wyjscie = QtGui.QPushButton(self.centralwidget)
self.Wyjscie.setGeometry(QtCore.QRect(350, 500, 201, 28))
self.Wyjscie.setObjectName(_fromUtf8("Wyjscie"))
self.label_3 = QtGui.QLabel(self.centralwidget)
self.label_3.setGeometry(QtCore.QRect(50, 160, 701, 31))
self.label_3.setObjectName(_fromUtf8("label_3"))
MainWindow.setCentralWidget(self.centralwidget)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow", None))
self.label.setText(_translate("MainWindow", "Funkcja Trygonometryczna", None))
self.label_2.setText(_translate("MainWindow", "Podaj wspolczynnik a: ", None))
self.Zatwierdz.setText(_translate("MainWindow", "Zatwierdz", None))
self.Wyjscie.setText(_translate("MainWindow", "Wyjscie", None))
self.label_3.setText(_translate("MainWindow", "Skrypt wyswietli wykres funkcji po wpisaniu wartosci ", None))
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
MainWindow = QtGui.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
【问题讨论】:
-
先修复代码格式