pyqt5 桌面宠物
时间: 2024-01-03 17:20:26 浏览: 43
以下是一个使用PyQt5制作的桌面宠物的示例代码,你可以根据自己的需要进行修改和定制:
```python
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QLabel
from PyQt5.QtGui import QPixmap
from PyQt5.QtCore import Qt, QTimer
class DesktopPet(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnBottomHint | Qt.Tool)
self.setAttribute(Qt.WA_TranslucentBackground)
self.setGeometry(100, 100, 200, 200)
self.label = QLabel(self)
self.label.setGeometry(0, 0, 200, 200)
self.label.setAlignment(Qt.AlignCenter)
self.timer = QTimer(self)
self.timer.timeout.connect(self.updateImage)
self.timer.start(1000)
self.show()
def updateImage(self):
pixmap = QPixmap('pet.png')
self.label.setPixmap(pixmap)
if __name__ == '__main__':
app = QApplication(sys.argv)
pet = DesktopPet()
sys.exit(app.exec_())
```
这个示例代码创建了一个桌面宠物窗口,它的形象是一个名为“pet.png”的图片。每隔1秒钟,它会更新一次图片,从而实现动态效果。
相关推荐
![exe](https://img-home.csdnimg.cn/images/20210720083343.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)