|
比如
现在一个窗口显示三个按钮,两个文本。
一个按钮是退出。另两个按钮点击可以改变一个文本的内容。
我想让另一个文本(label_rtc)显示一个时钟。
网上搜到一个例子(类MyTimer)。
代码如下:
class MyTimer(QWidget):
def __init__(self, parent = None):
super(MyTimer, self).__init__(parent)
self.resize(200, 100)
self.setWindowTitle("QTimerDemo")
self.lcd = QLCDNumber()
self.lcd.setDigitCount(10)
self.lcd.setMode(QLCDNumber.Dec)
self.lcd.setSegmentStyle(QLCDNumber.Flat)
self.lcd.display(time.strftime("%X",time.localtime()))
layout = QVBoxLayout()
layout.addWidget(self.lcd)
self.setLayout(layout)
#新建一个QTimer对象
self.timer = QTimer()
self.timer.setInterval(1000)
self.timer.start()
# 信号连接到槽
self.timer.timeout.connect(self.onTimerOut)
# 定义槽
def onTimerOut(self):
self.lcd.display(time.strftime("%X",time.localtime()))
class Pyqtp1(QtWidgets.QDialog, Ui_Dialog):
"""
Class documentation goes here.
"""
def __init__(self, parent=None):
"""
Constructor
@param parent reference to the parent widget
@type QWidget
"""
super(Pyqtp1, self).__init__(parent)
self.setupUi(self)
#@QtCore.pyqtSignature("")
@QtCore.pyqtSlot()
def on_btn1_clicked(self):
"""
Slot documentation goes here.
"""
# TODO: not implemented yet
self.label.setText(u"按钮1被按下!")
# raise NotImplementedError
#@QtCore.pyqtSignature("")
@QtCore.pyqtSlot()
def on_btn2_clicked(self):
"""
Slot documentation goes here.
"""
# TODO: not implemented yet
self.label.setText(u"按钮2被按下!")
# raise NotImplementedError
if __name__ == "__main__":
app = QApplication(sys.argv)
dlg = Pyqtp1()
dlg.show()
t = MyTimer()
t.show()
sys.exit(app.exec_())
现在是出来两个窗口,一个我之前的窗口,一个时钟窗口。
怎样做可以把时钟显示在之前窗口的文本label_rtc上?
|
阿莫论坛20周年了!感谢大家的支持与爱护!!
月入3000的是反美的。收入3万是亲美的。收入30万是移民美国的。收入300万是取得绿卡后回国,教唆那些3000来反美的!
|