0%

Python可视化

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
from PySide6 import QtGui
from PySide6.QtCore import QObject, Signal
from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton, QPlainTextEdit, QTextBrowser, QLabel, QComboBox

import time

from threading import Thread

class MySignals(QObject):
timeupdated = Signal()

class TestWindow():
def __init__(self):
self.defWidth = 800
self.defHeight = 450

self.app = QApplication()
self.mainWindow = QMainWindow()

self.tbw = None
self.lblLoudSpeaker = None
self.lblRunInfoPrompt = None
self.lblSoftwareInfo = None
self.lblDateTimeInfo = None

self.ms = MySignals()

def slot_update_time_info(self):
localtime = time.localtime(time.time())
dateTimeInfo = "{0}年{1:0>2d}月{2:0>2d}日 {3:0>2d}:{4:0>2d}:{5:0>2d}".format(localtime.tm_year, localtime.tm_mon, localtime.tm_mday, localtime.tm_hour, localtime.tm_min, localtime.tm_sec)
self.lblDateTimeInfo.setText(dateTimeInfo)
self.tbw.append("Hello world. I am sunshine panda. Now is {0}.".format(dateTimeInfo))

def update_time_info(self):
while True:
time.sleep(1)
# localtime = time.localtime(time.time())
# print ("本地时间为 :", localtime)
self.ms.timeupdated.emit()

def init_main_widget(self):
pixmap = QtGui.QPixmap("./res/img/cow.png")
self.mainWindow.setFixedSize(self.defWidth, self.defHeight)
self.mainWindow.setWindowTitle("勇敢牛牛,不敢困难")
self.mainWindow.setWindowIcon(pixmap)

self.tbw = QTextBrowser(self.mainWindow)
self.tbw.resize(self.defWidth - 50, self.defHeight - 50)
self.tbw.move(25, 25)

pixmap = QtGui.QPixmap("./res/img/loudspeaker.png")
self.lblLoudSpeaker = QLabel(self.mainWindow)
self.lblLoudSpeaker.resize(25, 25)
self.lblLoudSpeaker.move(0, 425)
self.lblLoudSpeaker.setPixmap(pixmap)
self.lblLoudSpeaker.setScaledContents(True)

self.lblRunInfoPrompt = QLabel(self.mainWindow)
self.lblRunInfoPrompt.resize(3 * self.defWidth / 8 - 50, 25)
self.lblRunInfoPrompt.move(50, 425)
self.lblRunInfoPrompt.setText("软件启动")

self.lblSoftwareInfo = QLabel(self.mainWindow)
self.lblSoftwareInfo.resize(3 * self.defWidth / 8, 25)
self.lblSoftwareInfo.move(3 * self.defWidth / 8, 425)
self.lblSoftwareInfo.setText("Designed by sunshine panda!")

self.lblDateTimeInfo = QLabel(self.mainWindow)
self.lblDateTimeInfo.resize(2 * self.defWidth / 8, 25)
self.lblDateTimeInfo.move(6 * self.defWidth / 8, 425)
self.lblDateTimeInfo.setText("2000-01-01 00:00:00")

self.ms.timeupdated.connect(self.slot_update_time_info)

upDateTimeThread = Thread(target=self.update_time_info, args=(), daemon=True)
upDateTimeThread.start()

def start_run(self):
self.mainWindow.show()
self.app.exec()

if __name__ == '__main__':
testWindow = TestWindow()
testWindow.init_main_widget()
testWindow.start_run()
testWindow.update_time_info()
GtGui实例
1
2
str = "<font color=\"#FF0000\">" + "content"+ "</font>"
textBrowser.append(str)