背景:因为项目需要,要开发一个在PC上运行的应用程序,生成一个跟随鼠标运动的窗口,并且监听鼠标的点击事件,并在窗口上做相应的显示。
平台:Win7 64位 + Python27 64位
支持库:PyHook + PyQt5
模块的安装这里就不多说了,网上有很多。需要注意的是,PyHook对Python3的支持不是很好,会出现卡死的问题, 还有PyQt5貌似只支持64位。废话不多说了,开始造~
第一步:
先用PyQt5生成一个自定义的窗口:
1 #!usr/bin/env python
2 #-*- coding:utf-8 -*-
3
4 importsys5 from PyQt5.QtCore import *
6 from PyQt5.QtGui import *
7 from PyQt5.QtWidgets import *
8
9 classnewWindow(QWidget):10 def __init__(self, parent=None):11 super(newWindow, self).__init__(parent)12 self.mypix()13 self.setWindowFlags(Qt.FramelessWindowHint) #去除界面边框
14 self.setWindowFlags(Qt.WindowStaysOnTopHint)#窗口显示在屏幕最上方
15 self.setAttribute(Qt.WA_TranslucentBackground)#背景透明
16
17 #显示不规则图片
18 defmypix(self):