pyqt5记录程序运行时间程序
时间: 2023-05-18 09:04:38 浏览: 73
可以使用Python内置的time模块来记录程序运行时间,下面是一个使用pyqt5编写的记录程序运行时间的示例代码:
```python
import sys
import time
from PyQt5.QtWidgets import QApplication, QWidget, QLabel
class App(QWidget):
def __init__(self):
super().__init__()
self.title = '记录程序运行时间'
self.left = 10
self.top = 10
self.width = 300
self.height = 200
self.initUI()
def initUI(self):
self.setWindowTitle(self.title)
self.setGeometry(self.left, self.top, self.width, self.height)
# 记录程序开始时间
start_time = time.time()
# 运行你的程序
# ...
# 记录程序结束时间
end_time = time.time()
# 计算程序运行时间
run_time = end_time - start_time
# 显示程序运行时间
label = QLabel(self)
label.setText("程序运行时间: {:.2f}秒".format(run_time))
label.move(50, 50)
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = App()
sys.exit(app.exec_())
```
这个程序使用了time模块来记录程序开始和结束的时间,然后计算程序运行时间,并在窗口中显示出来。你可以将“运行你的程序”这一行替换成你自己的程序代码。