![enter image description here](https://i.stack.imgur.com/xpuf0.jpg)
![enter image description here](https://i.stack.imgur.com/2UiBN.png)
Я сделал следующий код.Таймер работает правильно в консоли.Можно ли обновить код так, чтобы он отображался на экране моего созданного диалога.
Я использую PyQt5 в Python 3.6 в Windows.Я хочу создать нормальную кнопку входа пользователя.При первом входе в систему я хочу увидеть, как таймер начинает отсчет, как секундомер.
Заранее спасибо!
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'login.ui'
#
# Created by: PyQt5 UI code generator 5.5.1
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtWidgets, QtCore, QtGui, Qt
from PyQt5.QtCore import *
from PyQt5.QtGui import *
# from relogio import Ui_relogiocc
class Ui_Dialog(QtWidgets.QMainWindow):
def logincheck(self):
print("loged")
self.my_qtimer = QtCore.QTimer(self)
print("timer created")
self.my_qtimer.timeout.connect(self.timerTick)
self.my_qtimer.start(1000)
self.updateTimerDisplay()
def timerTick(self):
print("Control came")
self.inicio -= 1
if self.inicio <= 0:
self.timer.stop()
sys.exit(1)
self.updateTimerDisplay()
def updateTimerDisplay(self):
print("control to timer")
text = "%d:%02d" % (self.inicio / 60, self.inicio % 60)
print("value is ", text)
self.time_passed_qll.setText(str(text))
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(564, 461)
self.inicio = 180
# self.central_widget = QtWidgets.QWidget(Dialog)
# self.setCentralWidget(self.central_widget)
self.vbox = QtWidgets.QVBoxLayout()
# self.central_widget.addLayout(self.vbox)
self.time_passed_qll = QtWidgets.QLabel()
# self.timerStatus = QtWidgets.QGroupBox('time Status')
# self.timerStatusLayout = QtWidgets.QGridLayout()
# self.timerStatus.setLayout(self.timerStatusLayout)
# self.timerStatusLayout.addWidget(self.time_passed_qll, 0, 0)
# self.vbox.addWidget(self.time_passed_qll)
self.username_label = QtWidgets.QLabel(Dialog)
self.username_label.setGeometry(QtCore.QRect(27, 60, 91, 16))
self.username_label.setObjectName("username_label")
self.password_label = QtWidgets.QLabel(Dialog)
self.password_label.setGeometry(QtCore.QRect(30, 110, 68, 17))
self.password_label.setObjectName("password_label")
self.password_text = QtWidgets.QLineEdit(Dialog)
self.password_text.setGeometry(QtCore.QRect(190, 100, 241, 27))
self.password_text.setText("")
self.password_text.setEchoMode(QtWidgets.QLineEdit.Password)
self.password_text.setObjectName("password_text")
self.login_button = QtWidgets.QPushButton(Dialog)
self.login_button.setGeometry(QtCore.QRect(190, 190, 99, 27))
self.login_button.setObjectName("login_button")
###################################################
self.login_button.clicked.connect(self.logincheck)
self.reset_button = QtWidgets.QPushButton(Dialog)
self.reset_button.setGeometry(QtCore.QRect(330, 190, 99, 27))
self.reset_button.setObjectName("reset_button")
self.username_text = QtWidgets.QLineEdit(Dialog)
self.username_text.setGeometry(QtCore.QRect(200, 60, 241, 27))
self.username_text.setText("")
self.username_text.setObjectName("username_text")
################## to show widget in screen##########
self.vbox.addWidget(Dialog)
self.vbox.addWidget(self.time_passed_qll)
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
self.username_label.setText(_translate("Dialog", "User_Name"))
self.password_label.setText(_translate("Dialog", "Password"))
self.login_button.setText(_translate("Dialog", "Login"))
self.reset_button.setText(_translate("Dialog", "Reset"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Dialog = QtWidgets.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog.show()
sys.exit(app.exec_())