Δημοσιεύτηκε: 21 Νοέμ 2011, 00:05
από clepto
παλι λαθος μου το εδειχναν :twisted: :evil: :-x
οριστε
Κώδικας: Επιλογή όλων
#!/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(" ")
self.speed.selectAll()
rateLabel = QLabel("position")
self.position = QLineEdit(" ")
self.position.selectAll()
timeLabel = QLabel("time: ")
self.time = QLineEdit(" ")
self.resultLabel = QLabel()
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(okButton, 3, 1)
self.setLayout(grid)

self.connect(self.okButton,
SIGNAL("clicked()"), self.calculate)

self.setWindowTitle("Physic")

def calculate():
speed = self.speed.text()
position = self.position.text()
time = self.time.text()
if self.speed == " ":
result = position / time
elif self.position == " ":
result = speed * time
elif self.time == " ":
result = position / speed
self.resultLabel.setText(" " % result)

#app = QApplication(sys.argv)
#form = Form()
#form.show()
#app.exec_()

πιο πριν δεν γινεται γιατι παιρνω
Κώδικας: Επιλογή όλων
Traceback (most recent call last):
File "./physic2.pyw", line 9, in <module>
form = Form()
NameError: name 'Form' is not defined

και αν το βαλω μετα
Κώδικας: Επιλογή όλων
Traceback (most recent call last):
File "./physic2.pyw", line 58, in <module>
form = Form()
File "./physic2.pyw", line 40, in __init__
self.connect(self.okButton,
AttributeError: 'Form' object has no attribute 'okButton'