Código Python:
Ver original
import sys, os from PyQt4.QtGui import * from PyQt4.QtCore import * class Tempz(QWidget): def __init__(self, parent=None): super(Tempz, self).__init__(parent) self.timer = QTimer(self) self.lcd = QLCDNumber(self) self.spinbox = QSpinBox(self) self.spinbox2 = QSpinBox(self) self.bto = QPushButton('start', self) self.label = QLabel('Seconds',self) self.label2 = QLabel('Minutes', self) self.lineEdit = QLineEdit(self) self.label3 = QLabel('Command',self) self.start_time = self.spinbox.value() self.lcd.display("{0}:{1:02d}" .format(self.start_time/60,self.start_time % 60)) self.resize(300, 200) self.setWindowTitle('Crono') self.layout = QVBoxLayout(self) self.layout2 = QHBoxLayout(self) self.layout3 = QHBoxLayout(self) self.layout.addWidget(self.bto) self.layout.addWidget(self.lcd) self.layout2.addWidget(self.label) self.layout2.addWidget(self.spinbox) self.layout2.addWidget(self.label2) self.layout2.addWidget(self.spinbox2) self.layout2.setSpacing(10) self.layout3.addWidget(self.label3) self.layout3.addWidget(self.lineEdit) self.layout.addLayout(self.layout2) self.layout.addLayout(self.layout3) self.setLayout(self.layout) self.timer.timeout.connect(self.upTimer) self.bto.clicked.connect(self.cont) self.show() def cont(self): if self.spinbox.value(): self.start_time = self.spinbox.value()+self.spinbox2.value()*60 else: self.start_time = self.spinbox2.value()*60+self.spinbox.value() self.timer.stop() self.lcd.display("{0}:{1:02d}" .format(self.start_time/60,self.start_time % 60)) self.timer.start(1000) def upTimer(self): command = self.lineEdit.text() self.start_time -= 1 if self.start_time >= 6: self.lcd.display("{0}:{1:02d}" .format(self.start_time/60,self.start_time % 60)) elif self.start_time >= 1: self.lcd.display("{0}:{1:02d}" .format(self.start_time/60,self.start_time % 60)) os.system('beep -l 100') else: self.lcd.display("{0}:{1:02d}" .format(self.start_time/60,self.start_time % 60)) os.system('beep -l 500') self.timer.stop() os.system(str(command)) app = QApplication(sys.argv) tempz = Tempz() tempz.show() app.exec_()
Que funciona correctamente en python, pero arroja por terminal un error referente a los layouts:
Código:
Estoy buscando información de como gestionar estos layouts sin diseñador de intefaces, pues me resulta mas cómodo. He revisado la documentación de riverbank y de nokia, pero no acabo de entender el porqué de este error.QLayout: Attempting to add QLayout "" to Tempz "", which already has a layout
Sabeis donde está el error o donde encontrar información.
Saludos.