1
저는 파이썬을 처음 접했고 정말 도움이되기를 바랍니다.레이스 카운트 다운 위젯
자동 슬롯 차량 랩 카운트/타이머 용 앱을 만들려고합니다. 레이스가 시작되기 전에 카운트 다운이 필요합니다. QLabel을 사용하고 있습니다.
'update_label()'함수로 업데이트하고 싶지만 작동하지 않습니다.
내가 뭘 잘못 했니?
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import sys, time
from PyQt5.QtWidgets import QWidget, QPushButton, QLabel, QLineEdit, QGridLayout, QApplication, QLCDNumber, QSlider
from PyQt5.QtCore import QCoreApplication, Qt
class race(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
lane1 = QLabel('READY?')
grid = QGridLayout()
grid.setSpacing(10)
grid.addWidget(lane1, 1, 0, 1, 1)
self.setLayout(grid)
self.setGeometry(400, 300, 600, 300)
self.setWindowTitle('Race')
self.showMaximized()
self.update_label()
def update_label(self):
count = 3
while count>1:
time.sleep(1)
counter = count
Label = self.lane1.setText(counter)
timer = QtCore.QTimer()
timer.timeout.connect(Label)
timer.start(10000)
count = count - 1
if __name__ == '__main__':
raceApp = QApplication(sys.argv)
racePanel = race()
sys.exit(raceApp.exec_())
은 그러나이 오류가 발생합니다 :
Traceback (most recent call last):
File "./race.py", line 58, in <module>
racePanel = race()
File "./race.py", line 16, in __init__
self.initUI()
File "./race.py", line 35, in initUI
self.update_label()
File "./race.py", line 45, in update_label
Label = self.lane1.setText(counter)
AttributeError: 'race' object has no attribute 'lane1'
@CroMagnon. 편집 할 때 서명 줄, "감사"등을 제거하십시오. 이는 노이즈로 간주됩니다. [ "안녕, 고마워, 태그 라인 및 인사말을 게시물에서 삭제해야합니까"] (http://meta.stackexchange.com/questions/2950/should-hi-thanks-taglines-and-salutations-be-removed-from- 게시물). –
timer.timeout.connect는 슬롯 (파이썬에서 호출 가능)에 연결해야하며, Label은 setText에서 반환하는 것과 비슷하지 않을 수 있습니다. 이것은 호출 가능하지 않습니다. Qt의 신호와 슬롯에 대해서 더 읽고, 일반적으로 파이썬에 대해서도 읽어보십시오. – Trilarion