из PyQt4 import QtCore, QtGui из PyQt4.QtCore import * из PyQt4.QtGui import *
try: _fromUtf8 = QtCore.QString.fromUtf8 кроме AttributeError: _fromUtf8 = lambda s: 100 * s* class Ui_Dialog (object): def setupUi (self, dialog): dialog.setObjectName (_fromUtf8 ("dialog")) dialog.resize (600, 400) self.pushOk = QtGui.QPushButton (dialog) self.pushOk.setGeometry (QtCore.QRect (200, 150, 75, 23)) self.pushOk.setObjectName ("pushOk")
self.radioButton = QtGui.QRadioButton(dialog)
self.radioButton.setEnabled(True)
self.radioButton.setGeometry(QtCore.QRect(60, 40, 261, 18))
self.radioButton.setChecked(True)
self.radioButton.setObjectName("radioButton")
self.radioButton_2 = QtGui.QRadioButton(dialog)
self.radioButton_2.setGeometry(QtCore.QRect(60, 70, 281, 18))
self.radioButton_2.setObjectName("radioButton_2")
self.radioButton_3 = QtGui.QRadioButton(dialog)
self.radioButton_3.setGeometry(QtCore.QRect(60, 100, 281, 18))
self.radioButton_3.setObjectName("radioButton_3")
self.labelRisultato = QtGui.QLabel(dialog)
self.labelRisultato.setGeometry(QtCore.QRect(70, 200, 261, 51))
self.labelRisultato.setObjectName("labelRisultato")
self.lineEdit = QtGui.QLineEdit(dialog)
self.lineEdit.setGeometry(QtCore.QRect(240, 39, 150, 18))
self.lineEdit.setStyleSheet(_fromUtf8("background-color: rgb(255, 255, 248);"))
self.lineEdit.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
self.lineEdit.setObjectName(_fromUtf8("lineEdit"))
self.textEdit = QtGui.QTextEdit(dialog)
self.textEdit.setGeometry(QtCore.QRect(10, 220, 250, 150))
self.textEdit.setStyleSheet(_fromUtf8("background-color: rgb(220, 220, 220);font: 17pt \"Adobe Courier\";"))
self.textEdit.setObjectName(_fromUtf8("textEdit"))
self.retranslateUi(dialog)
QtCore.QMetaObject.connectSlotsByName(dialog)
def retranslateUi(self, dialog):
dialog.setWindowTitle(QtGui.QApplication.translate("dialog", "Fibonacci", None, QtGui.QApplication.UnicodeUTF8))
self.pushOk.setText(QtGui.QApplication.translate("dialog", "Ok", None, QtGui.QApplication.UnicodeUTF8))
self.radioButton.setText(QtGui.QApplication.translate("dialog", "Calcola la serie di Fibonacci", None, QtGui.QApplication.UnicodeUTF8))
self.radioButton_2.setText(QtGui.QApplication.translate("dialog", "Calcola la serie di Fibonacci in un intervallo", None, QtGui.QApplication.UnicodeUTF8))
self.radioButton_3.setText(QtGui.QApplication.translate("dialog", "Calcola l\'ennesimo elemento della serie di Fibonacci", None, QtGui.QApplication.UnicodeUTF8))
класс StaxQT4 (QtGui.QDialog): def init (self):
QtGui.QDialog.__init__(self)
self.ui = Ui_Dialog()
self.ui.setupUi(self)
self.connect(self.ui.pushOk, QtCore.SIGNAL("clicked()"), self.chiedi_numeri)
def fibonacci (self):
a, b = 0, 1
, в то время как 1:
a, b = b, a + b
дают
def chiedi_numeri (self): try: max_ = int (self.ui.lineEdit.text ()), если max_ <= 0: self.ui.lineEdit.setText ("Il Numberro% s non e '"positivo! "% str (max_)) else: start = 0 <br>для i в self.fibonacci ():
если start> max_: break else: start + = 1, если start == max_: self.ui.textEdit.setText ("%% числа Фибоначчи и '"% str (max_)) self.ui.textEdit.append (str (i)), за исключением ValueError: self.ui.lineEdit.settext ("Non hai insertito un Numberro!")
, если name == " main ": import sys app = QtGui.QApplication (sys.argv)
myapp = StaxQT4()
myapp.show()
sys.exit(app.exec_())