應該算簡單了,可以直接拿去用。字型和位置可以自己調。效果圖看最下面gif圖
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import QTimer,QDateTime
import sys
class Ui_Form(object):
def setupUi(self, Form):
Form.resize(1098, 842) #設定可視化界面長1098,寬842
self.label_100 = QtWidgets.QLabel(Form) #Ui界面裡建立一個可視化界面label_100
self.label_100.setGeometry(QtCore.QRect(410, 0, 360, 41)) #label_100裡面設定框的大小為左右410,上下0,寬360,高41
self.Timer=QTimer() #自定義QTimer
self.Timer.start(500) #每0.5秒運作一次
self.Timer.timeout.connect(self.updateTime) #連接配接updateTime
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def updateTime(self):
self.label_100.setText(QDateTime.currentDateTime().toString('yyyy-MM-dd hh:mm:ss dddd')) #顯示時間的格式
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_Form()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
