اذهب إلى المحتوى

السؤال

Recommended Posts

  • 0
نشر (معدل)

تم الحل هنا PyQt5-link

from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_Dialog(object):
    def setupUi(self, Dialog):
        Dialog.setObjectName("Dialog")
        Dialog.resize(554, 401)
        self.pushButton5 = QtWidgets.QPushButton(Dialog)
        self.pushButton5.setGeometry(QtCore.QRect(110, 220, 93, 28))
        self.pushButton5.setObjectName("pushButton5")
        self.pushButton8 = QtWidgets.QPushButton(Dialog)
        self.pushButton8.setGeometry(QtCore.QRect(220, 220, 93, 28))
        self.pushButton8.setObjectName("pushButton8")
        self.pushButton12 = QtWidgets.QPushButton(Dialog)
        self.pushButton12.setGeometry(QtCore.QRect(320, 220, 93, 28))
        self.pushButton12.setObjectName("pushButton12")
        self.label_2 = QtWidgets.QLabel(Dialog)
        self.label_2.setGeometry(QtCore.QRect(104, 150, 101, 20))
        font = QtGui.QFont()
        font.setPointSize(9)
        font.setBold(True)
        font.setItalic(False)
        font.setWeight(75)
        self.label_2.setFont(font)
        self.label_2.setObjectName("label_2")
        self.speed = QtWidgets.QLineEdit(Dialog)
        self.speed.setGeometry(QtCore.QRect(220, 150, 113, 22))
        self.speed.setObjectName("speed")
        self.result = QtWidgets.QLabel(Dialog)
        self.result.setGeometry(QtCore.QRect(130, 180, 301, 21))
        self.result.setText("")
        self.result.setObjectName("result")

        self.retranslateUi(Dialog)
        QtCore.QMetaObject.connectSlotsByName(Dialog)
        self.initUI() #New

    def retranslateUi(self, Dialog):
        _translate = QtCore.QCoreApplication.translate
        Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
        self.pushButton5.setText(_translate("Dialog", "5"))
        self.pushButton8.setText(_translate("Dialog", "8"))
        self.pushButton12.setText(_translate("Dialog", "12"))
        self.label_2.setText(_translate("Dialog", "Enter Speed"))

    def initUI(self): #New
        self.pushButton5.clicked.connect(lambda x: self.calc_distance(5)) #New
        self.pushButton8.clicked.connect(lambda x: self.calc_distance(8)) #New
        self.pushButton12.clicked.connect(lambda x: self.calc_distance(12))#New
        
    def calc_distance(self,index):#New
        speed = float(self.speed.text()) #New
        time_ = float(index)#New
        distance = speed*time_ #New
        print(distance, " :KM") #New
        self.result.setText(str(distance)) #New

if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    Dialog = QtWidgets.QDialog()
    ui = Ui_Dialog()
    ui.setupUi(Dialog)
    Dialog.show()
    sys.exit(app.exec_())

 

تم التعديل في بواسطة Mohammed_Emad

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...