[TOC]
# 设置窗口图标
~~~
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
import sys
# 创建个应用程序 需要加上参数
app = QApplication(sys.argv)
# 创建窗口
widget = QWidget()
# 修改窗口大小
widget.resize(300, 400)
#设置窗口的标题
widget.setWindowTitle('设置窗口图标')
# 修改窗口图标
icon = QIcon('11.png')
widget.setWindowIcon(icon)
# 显示窗口
widget.show()
# 系统安全退出
sys.exit(app.exec())
~~~
# 移动窗口
![](https://box.kancloud.cn/1f37fb1f738d1f4a5307d443a9dd06e2_692x466.png)
`x = 屏幕width/2-窗口/2`
y同理
移动到中心所需方法
| 方法 | 调用对象 | 方法说明 |
| --- | --- | --- |
| screenGeometry() | QDesktopWidget() | 获取屏幕尺寸 |
| geometry() | QMainWindow() | 获取窗口尺寸 |
| move(x, y) | QMainWindow() | 移动到指定的位置 |
~~~
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
import sys
# 创建个应用程序 需要加上参数
app = QApplication(sys.argv)
# 创建窗口
widget = QWidget()
# 修改窗口大小
widget.resize(300, 400)
# 设置窗口的标题
widget.setWindowTitle('移动窗口到指定位置')
# 获取屏幕尺寸
screen = QDesktopWidget().screenGeometry()
# 获取窗口尺寸
wg = widget.geometry()
# x 屏幕宽度/2 - 窗口width/2
x = screen.width() / 2 - wg.width() / 2
# y 屏幕高度/2 - 窗口height/2
y = screen.height() / 2 - wg.height() / 2
# 移动
# 中间
# widget.move(x, y)
# x右边一点点
widget.move(x + 200, y)
# 显示窗口
widget.show()
# 系统安全退出
sys.exit(app.exec())
~~~