initial commit
This commit is contained in:
commit
5613f79151
8
QT/PyQt/.idea/.gitignore
generated
vendored
Normal file
8
QT/PyQt/.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# 默认忽略的文件
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# 基于编辑器的 HTTP 客户端请求
|
||||||
|
/httpRequests/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
8
QT/PyQt/.idea/PyQt.iml
generated
Normal file
8
QT/PyQt/.idea/PyQt.iml
generated
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="PYTHON_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="jdk" jdkName="Python 3.12" jdkType="Python SDK" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
18
QT/PyQt/.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
18
QT/PyQt/.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<profile version="1.0">
|
||||||
|
<option name="myName" value="Project Default" />
|
||||||
|
<inspection_tool class="DuplicatedCode" enabled="false" level="WEAK WARNING" enabled_by_default="false">
|
||||||
|
<Languages>
|
||||||
|
<language minSize="50" name="Python" />
|
||||||
|
</Languages>
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="PyPep8Inspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
||||||
|
<option name="ignoredErrors">
|
||||||
|
<list>
|
||||||
|
<option value="E501" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="PyRedeclarationInspection" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||||
|
</profile>
|
||||||
|
</component>
|
6
QT/PyQt/.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
6
QT/PyQt/.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<settings>
|
||||||
|
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||||
|
<version value="1.0" />
|
||||||
|
</settings>
|
||||||
|
</component>
|
7
QT/PyQt/.idea/misc.xml
generated
Normal file
7
QT/PyQt/.idea/misc.xml
generated
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Black">
|
||||||
|
<option name="sdkName" value="Python 3.12" />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12" project-jdk-type="Python SDK" />
|
||||||
|
</project>
|
8
QT/PyQt/.idea/modules.xml
generated
Normal file
8
QT/PyQt/.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/PyQt.iml" filepath="$PROJECT_DIR$/.idea/PyQt.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
29
QT/PyQt/1. 第一个QT程序.py
Normal file
29
QT/PyQt/1. 第一个QT程序.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#!D:\Python311\python.exe
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# @Time : 2024/2/26 13:02
|
||||||
|
# @Author : DC_DC
|
||||||
|
"""# 打印版本信息
|
||||||
|
from PyQt6.QtCore import PYQT_VERSION_STR, QT_VERSION_STR
|
||||||
|
print(QT_VERSION_STR)
|
||||||
|
print(PYQT_VERSION_STR)"""
|
||||||
|
|
||||||
|
import sys # 处理python解释器和系统的交互
|
||||||
|
from PyQt6.QtWidgets import QApplication, QMainWindow, QLabel
|
||||||
|
from PyQt6.QtGui import QIcon # 设置窗口的图标
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
app = QApplication(sys.argv) # 创建一个QApplication对象,用于管理GUI应用程序的控制流和主事件循环
|
||||||
|
window = QMainWindow() # 创建一个QMainWindow对象,这是程序的主窗口
|
||||||
|
window.setGeometry(500, 500, 300, 200) # 设置窗口的集合属性,即窗口在屏幕上的位置大小
|
||||||
|
window.setWindowTitle("DC_DC") # 设置窗口标题
|
||||||
|
window.setWindowIcon(QIcon('Photos/img.png')) # 设置窗口图标
|
||||||
|
QLabel("Hello, World!", window) # 创建一个QLabel对象,并将其添加到主窗口中
|
||||||
|
window.show() # 显示主窗口
|
||||||
|
sys.exit(app.exec()) # 调用QApplication对象的exec()方法,进入GUI应用程序的主事件循环,sys.exit()则确保程序在退出事件循环侯正确地退出,并返回一个退出码0
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|
||||||
|
pass
|
32
QT/PyQt/2. 居中显示窗口.py
Normal file
32
QT/PyQt/2. 居中显示窗口.py
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
#!D:\Python311\python.exe
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# @Time : 2024/2/26 13:34
|
||||||
|
# @Author : DC_DC
|
||||||
|
import sys
|
||||||
|
from PyQt6.QtWidgets import QApplication, QWidget, QLabel
|
||||||
|
from PyQt6.QtGui import QGuiApplication
|
||||||
|
from PyQt6.QtGui import QIcon
|
||||||
|
|
||||||
|
|
||||||
|
class MyApplication(QWidget):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
self.init_ui()
|
||||||
|
|
||||||
|
def init_ui(self):
|
||||||
|
self.setGeometry(0, 0, 300, 200)
|
||||||
|
self.setWindowIcon(QIcon('Photos/img.png'))
|
||||||
|
qr = self.frameGeometry() # 创建一个矩形对象qr,它表示窗口的几何形状
|
||||||
|
|
||||||
|
cp = QGuiApplication.primaryScreen().availableGeometry().center() # 获取主屏幕的几何属性,计算出屏幕中心点的坐标
|
||||||
|
qr.moveCenter(cp) # 将窗口的几何形状移动到屏幕中心
|
||||||
|
self.move(qr.topLeft()) # 将窗口移动到矩形的左上角,以实现窗口剧中显示的效果
|
||||||
|
|
||||||
|
QLabel('Hello World!', self)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
app = QApplication(sys.argv)
|
||||||
|
ex = MyApplication()
|
||||||
|
ex.show() # 调用父类方法,显示窗口
|
||||||
|
sys.exit(app.exec())
|
54
QT/PyQt/3. QMainWindow主要内容.py
Normal file
54
QT/PyQt/3. QMainWindow主要内容.py
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
#!D:\Python311\python.exe
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# @Time : 2024/2/26 14:01
|
||||||
|
# @Author : DC_DC
|
||||||
|
"""
|
||||||
|
QMainWindow是QT框架中的一个类,用于创建主窗口应用程序,提供一个具有一般应用程序框架的主窗口,包括菜单栏、工具栏、状态栏和中央工作区域
|
||||||
|
使用这个类可以管理主窗口
|
||||||
|
1. 主窗口标题
|
||||||
|
2. 主窗口标签
|
||||||
|
3. 菜单栏
|
||||||
|
4. 工具栏
|
||||||
|
5. 状态栏
|
||||||
|
"""
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from PyQt5.QtWidgets import QApplication, QMainWindow, QLabel
|
||||||
|
|
||||||
|
|
||||||
|
class MyMainWindow(QMainWindow):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
# 设置主窗口标题
|
||||||
|
self.setWindowTitle('My Main Window')
|
||||||
|
# 添加标签到中央工作区域
|
||||||
|
central_widget = QLabel("Hello, QMainWindow!")
|
||||||
|
self.setCentralWidget(central_widget)
|
||||||
|
# 添加菜单栏
|
||||||
|
menubar = self.menuBar()
|
||||||
|
file_menu = menubar.addMenu('File')
|
||||||
|
file_menu.addAction('Open')
|
||||||
|
file_menu.addAction('Save')
|
||||||
|
# 添加工具栏
|
||||||
|
toolbar = self.addToolBar('Tools')
|
||||||
|
toolbar.addAction('Cut')
|
||||||
|
toolbar.addAction('Copy')
|
||||||
|
toolbar.addAction('Paste')
|
||||||
|
# 添加状态栏
|
||||||
|
statusbar = self.statusBar()
|
||||||
|
statusbar.showMessage('Ready')
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
app = QApplication([]) # 这种写法和下面的写法一致
|
||||||
|
"""
|
||||||
|
为什么要实例化这个类呢?
|
||||||
|
1. 管理应用程序的事件循环
|
||||||
|
2. 管理应用程序的全局状态
|
||||||
|
3,处理命令行参数
|
||||||
|
记住,创建一个QApplication对象是整个PyQT5应用程序的入口点
|
||||||
|
"""
|
||||||
|
# app = QApplication(sys.argv if sys.argv else [])
|
||||||
|
window = MyMainWindow()
|
||||||
|
window.show()
|
||||||
|
app.exec_()
|
40
QT/PyQt/4. 多页面切换实例.py
Normal file
40
QT/PyQt/4. 多页面切换实例.py
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
#!D:\Python311\python.exe
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# @Time : 2024/2/28 16:09
|
||||||
|
# @Author : DC_DC
|
||||||
|
import sys
|
||||||
|
from PyQt6.QtWidgets import QApplication, QMainWindow, QTabWidget, QVBoxLayout, QPushButton, QWidget, QHBoxLayout
|
||||||
|
from PyQt6.QtGui import QIcon
|
||||||
|
|
||||||
|
|
||||||
|
class MainWindow(QMainWindow):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
self.setWindowTitle("DC_DC") # 设置窗口标题
|
||||||
|
self.setWindowIcon(QIcon('Photos/img.png')) # 设置图标
|
||||||
|
self.setGeometry(100, 100, 800, 600) # 设置窗口大小
|
||||||
|
self.tab_widget = QTabWidget() # 创建了一个QTabWidget实例,用于容纳标签页。
|
||||||
|
self.setCentralWidget(self.tab_widget) # 设置标签页空间位置
|
||||||
|
self.page1 = QWidget() # 创建页面1
|
||||||
|
self.page2 = QWidget() # 创建页面2
|
||||||
|
self.tab_widget.addTab(self.page1, "页面1") # 添加页面1到QTabWidget
|
||||||
|
self.tab_widget.addTab(self.page2, "页面2") # 添加页面2到QTabWidget
|
||||||
|
layout = QVBoxLayout() # 定义一个垂直布局对象,用来组织两个按钮 如果设置水平就实例化QHBoxLayout 一个布局对象只能被设置给一个父对象
|
||||||
|
button1 = QPushButton("切换到页面1") # 定义一个按钮
|
||||||
|
button1.clicked.connect(lambda: self.switch_page(1)) # 设置按钮的映射关系
|
||||||
|
button2 = QPushButton("切换到页面2") # 定义一个按钮
|
||||||
|
button2.clicked.connect(lambda: self.switch_page(2)) # 设置按钮的映射关系
|
||||||
|
layout.addWidget(button1) # 添加按钮1到垂直布局对象
|
||||||
|
layout.addWidget(button2) # 添加按钮2到垂直布局对象
|
||||||
|
self.page2.setLayout(layout) # 按照布局规则进行摆放页面
|
||||||
|
self.page1.setLayout(layout) # 按照布局规则进行摆放页面
|
||||||
|
|
||||||
|
def switch_page(self, index):
|
||||||
|
self.tab_widget.setCurrentIndex(index - 1)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
app = QApplication([]) # 创建一个应用程序对象
|
||||||
|
mainWin = MainWindow()
|
||||||
|
mainWin.show()
|
||||||
|
sys.exit(app.exec())
|
BIN
QT/PyQt/Photos/img.png
Normal file
BIN
QT/PyQt/Photos/img.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.9 KiB |
Loading…
x
Reference in New Issue
Block a user