基于Python的鼠标追踪器

Python版本:3.10.8

库: PyQt6、pyautogui、sys

有帮助的话,点个赞再走呗,谢谢啦~

完整代码↓


from PyQt6 import QtCore, QtGui, QtWidgets
from PyQt6.QtCore import QTimer
import pyautogui

class Ui_mouse_tracer(object):
    def setupUi(self, mouse_tracer):
        mouse_tracer.setObjectName("mouse_tracer")
        mouse_tracer.resize(250, 100)
        self.widget = QtWidgets.QWidget(mouse_tracer)
        self.widget.setGeometry(QtCore.QRect(16, 10, 181, 81))
        self.widget.setObjectName("widget")
        self.gridLayout = QtWidgets.QGridLayout(self.widget)
        self.gridLayout.setContentsMargins(0, 0, 0, 0)
        self.gridLayout.setObjectName("gridLayout")
        self.position = QtWidgets.QLabel(self.widget)
        self.position.setObjectName("position")
        self.gridLayout.addWidget(self.position, 0, 0, 1, 1)
        self.screen = QtWidgets.QLabel(self.widget)
        self.screen.setObjectName("screen")
        self.gridLayout.addWidget(self.screen, 1, 0, 1, 1)
        self.retranslateUi(mouse_tracer)
        QtCore.QMetaObject.connectSlotsByName(mouse_tracer)
        self.Timer()

    def retranslateUi(self, mouse_tracer):
        _translate = QtCore.QCoreApplication.translate
        mouse_tracer.setWindowTitle(_translate("mouse_tracer", "mouse_tracer"))
        self.position.setText(_translate("mouse_tracer", ""))
        self.screen.setText(_translate("mouse_tracer", str(pyautogui.size())))

    def Timer(self):
        self.timer = QTimer()
        self.timer.timeout.connect(self.tracing)        # 设定PyQt6的计时器
        self.timer.start(200)
    def tracing(self):
        a = pyautogui.position()                        # 用pyautogui获取鼠标位置
        self.position.setText(str(a))


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    mouse_tracer = QtWidgets.QWidget()
    ui = Ui_mouse_tracer()
    ui.setupUi(mouse_tracer)
    mouse_tracer.show()
    sys.exit(app.exec())

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值