Δημοσιεύτηκε: 21 Νοέμ 2011, 00:50
- Κώδικας: Επιλογή όλων
#!/usr/bin/env python
import sys
from math import *
from PyQt4.QtCore import *
from PyQt4.QtGui import *
app = QApplication(sys.argv)
#form = Form()
#form.show()
#app.exec_()
class Form(QDialog):
def __init__(self, parent=None):
super(Form, self).__init__(parent)
principalLabel = QLabel("speed")
self.speed = QLineEdit("")
rateLabel = QLabel("position")
self.position = QLineEdit("")
timeLabel = QLabel("time: ")
self.time = QLineEdit("")
self.resultLabel = QLabel()
self.okButton = QPushButton("OK")
grid = QGridLayout()
grid.addWidget(principalLabel, 0, 0)
grid.addWidget(self.speed, 0, 1)
grid.addWidget(rateLabel, 1, 0)
grid.addWidget(self.position, 1, 1)
grid.addWidget(timeLabel, 2, 0)
grid.addWidget(self.time, 2, 1)
grid.addWidget(self.resultLabel, 3, 0)
grid.addWidget(self.okButton, 4, 1)
self.setLayout(grid)
self.connect(self.okButton,
SIGNAL("clicked()"), self.calculate)
self.setWindowTitle("Physic")
def calculate(self):
speed = self.speed.text()
position = self.position.text()
time = self.time.text()
if self.speed == " ":
result = position / time
self.resultLabel.setText(" " % result)
elif self.position == " ":
result = speed * time
self.resultLabel.setText(" " % result)
elif self.time == " ":
result = position / speed
self.resultLabel.setText(" " % result)
#self.resultLabel.setText(" " % result)
#app = QApplication(sys.argv)
form = Form()
form.show()
app.exec_()