python pyqt5项目开发实例
时间: 2023-09-05 11:07:37 浏览: 195
您可以关注『Python 小白从零开始 PyQt5 项目实战 @ Youcans』系列,其中包括了从安装与环境配置,到菜单和工具栏,信号与槽的连接,基本控件,布局管理,窗口切换的堆叠布局,折叠侧边栏的实现等多个实战项目示例。此外,您可以使用pip安装Qt Tools,以便使用QtDesigner和PyUIC进行环境配置。关于您提到的Python PyQt5项目开发实例,下面是一个示例代码,通过点击按钮来展示5秒后的时间:
```python
import sys
import datetime
import time
from ui import Ui_MainWindow
from PyQt5.QtWidgets import QMainWindow, QApplication
class MyWindow(QMainWindow, Ui_MainWindow):
def __init__(self):
super(MyWindow, self).__init__()
self.setupUi(self)
self.pushButton.clicked.connect(self.change_text)
def change_text(self):
time.sleep(5)
self.plainTextEdit.setPlainText((datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')))
if __name__ == '__main__':
app = QApplication(sys.argv)
myWin = MyWindow()
myWin.show()
sys.exit(app.exec_())
```
这段代码中,我们定义了一个窗口类`MyWindow`,继承自`QMainWindow`和`Ui_MainWindow`,其中`Ui_MainWindow`是通过QtDesigner设计的界面。在按钮的点击事件中,我们使用`time.sleep(5)`来让程序休眠5秒钟,然后再输出当前时间到文本框中。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [Python 小白从零开始 PyQt5 项目实战(8)汇总篇(完整例程)](https://blog.csdn.net/youcans/article/details/120925109)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
- *3* [Python Pyqt5快速上手教程](https://blog.csdn.net/weixin_43908875/article/details/128419990)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文