#!/usr/bin/env python # -*- coding: utf-8 -*- # # The PYTHagoras application by Kris # import sys from qt import * import math class Pytagoras(QWidget): def __init__(self, *args): QWidget.__init__(self, *args) self.setCaption("PYTHagoras - 0.1") self.setGeometry(0,0,230,130) # Button, Text and Inputs self.kateteEtText = QLabel("Katete1:", self) self.kateteEtText.setGeometry(10,10,100,25) self.kateteToText = QLabel("Katete2:", self) self.kateteToText.setGeometry(10,40,100,25) self.kateteEt = QLineEdit("", self) self.kateteEt.setGeometry(90,10,100,25) self.kateteTo = QLineEdit("", self) self.kateteTo.setGeometry(90,40,100,25) self.cmEtText = QLabel("cm", self) self.cmEtText.setGeometry(195,10,100,25) self.cmToText = QLabel("cm", self) self.cmToText.setGeometry(195,40,100,25) self.hypetenuseText = QLabel("C = ", self) self.hypetenuseText.setGeometry(40,70,100,25) self.calculate = QPushButton("Udregn!", self) self.calculate.setGeometry(70,100,100,25) #Actions self.connect(self.calculate, SIGNAL("clicked()"), self.doCalculate) # Functions def doShowCalculate(self): a2 = math.pow(a,2) b2 = math.pow(b,2) c = math.sqrt(c2) print "A2 = ", a2 print "B2 = ", b2 print "C2 = ", a2+b2 print "\nC = ", c def doCalculate(self): a = float(self.kateteEt.text()) b = float(self.kateteTo.text()) c2 = math.pow(a,2)+math.pow(b,2) c = math.sqrt(c2) print "C = ", c # Main if __name__ == "__main__": app = QApplication(sys.argv) app.connect(app, SIGNAL("lastWindowClosed()"), app, SLOT('quit()')) pytagoras = Pytagoras() pytagoras.show() app.setMainWidget(pytagoras) app.exec_loop()