白银建设工程网站,广州网络营销公司,手表网站代码,seo关键词软件前言 这里是【使用Python编写游戏辅助工具】的第五篇#xff1a;打造交互式游戏工具界面#xff1a;PySide6/PyQT高效构建GUI工具。本文主要介绍使用PySide6来实现构建GUI工具。 在前面#xff0c;我们实现了两个实用的游戏辅助功能#xff1a;
由键盘监听事件触发的鼠标连…
前言 这里是【使用Python编写游戏辅助工具】的第五篇打造交互式游戏工具界面PySide6/PyQT高效构建GUI工具。本文主要介绍使用PySide6来实现构建GUI工具。 在前面我们实现了两个实用的游戏辅助功能
由键盘监听事件触发的鼠标连击功能对Windows窗口的多种操作如隐藏、显示、设置前台等
在这一篇文章中笔者将带领读者朋友们使用 PySide6/PyQT 将前面实现的功能封装成一个GUI工具这样一个简单的游戏辅助工具初具雏形了。
即使你完全没有 PySide6/PyQT 这方面的开发经验也没关系学习就完事了
即便不想学习笔者也会提供源码拿来用就完事了。
本文章为本系列文章最后一篇【使用Python编写游戏辅助工具】系列文章到此结束。 文章脉络概述
该工具大致的组织架构如下图所示
包含 鼠标连击、Windows窗口操作等功能 #mermaid-svg-0OaookKNkVPI1C3H {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-0OaookKNkVPI1C3H .error-icon{fill:#552222;}#mermaid-svg-0OaookKNkVPI1C3H .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-0OaookKNkVPI1C3H .edge-thickness-normal{stroke-width:2px;}#mermaid-svg-0OaookKNkVPI1C3H .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-0OaookKNkVPI1C3H .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-0OaookKNkVPI1C3H .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-0OaookKNkVPI1C3H .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-0OaookKNkVPI1C3H .marker{fill:#333333;stroke:#333333;}#mermaid-svg-0OaookKNkVPI1C3H .marker.cross{stroke:#333333;}#mermaid-svg-0OaookKNkVPI1C3H svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-0OaookKNkVPI1C3H .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-0OaookKNkVPI1C3H .cluster-label text{fill:#333;}#mermaid-svg-0OaookKNkVPI1C3H .cluster-label span{color:#333;}#mermaid-svg-0OaookKNkVPI1C3H .label text,#mermaid-svg-0OaookKNkVPI1C3H span{fill:#333;color:#333;}#mermaid-svg-0OaookKNkVPI1C3H .node rect,#mermaid-svg-0OaookKNkVPI1C3H .node circle,#mermaid-svg-0OaookKNkVPI1C3H .node ellipse,#mermaid-svg-0OaookKNkVPI1C3H .node polygon,#mermaid-svg-0OaookKNkVPI1C3H .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-0OaookKNkVPI1C3H .node .label{text-align:center;}#mermaid-svg-0OaookKNkVPI1C3H .node.clickable{cursor:pointer;}#mermaid-svg-0OaookKNkVPI1C3H .arrowheadPath{fill:#333333;}#mermaid-svg-0OaookKNkVPI1C3H .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-0OaookKNkVPI1C3H .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-0OaookKNkVPI1C3H .edgeLabel{background-color:#e8e8e8;text-align:center;}#mermaid-svg-0OaookKNkVPI1C3H .edgeLabel rect{opacity:0.5;background-color:#e8e8e8;fill:#e8e8e8;}#mermaid-svg-0OaookKNkVPI1C3H .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-0OaookKNkVPI1C3H .cluster text{fill:#333;}#mermaid-svg-0OaookKNkVPI1C3H .cluster span{color:#333;}#mermaid-svg-0OaookKNkVPI1C3H div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-0OaookKNkVPI1C3H :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} 辅助工具 鼠标连击 Windows窗口操作 在本系列文章中我们将逐步构建一个游戏辅助工具它将提供以下主要功能所有功能都是借助Python的相关库和模块来帮助我们实现的 鼠标连击器实现自动触发连续鼠标点击动作帮助我们实现连击操作 Windows窗口操作利用Python的相关库和模块我们将探索如何操作和控制Windows窗口包括隐藏窗口、显示窗口、置顶窗口等操作
系列文章脉络 系列文章内容大体如下后续可能会更新新的文章。 点击直达【使用Python编写游戏辅助工具】第一篇概述 点击直达【使用Python编写游戏辅助工具】第二篇键盘监听的应用 点击直达【使用Python编写游戏辅助工具】第三篇鼠标连击器的实现 点击直达【使用Python编写游戏辅助工具】第四篇Windows窗口操作 点击直达【使用Python编写游戏辅助工具】第五篇打造交互式游戏工具界面PySide6/PyQT高效构建GUI工具
知识点
库和模块描述PySide6/PyQT提供了Python与Qt框架的绑定用于创建图形用户界面GUI
安装依赖
pip install pyside6这个模块就可以很好的实现本文的主题。
实现 因文章篇幅有限抓重点来讲。 本文的代码实在是太多了也不知从哪说起。干脆把代码都贴上来
操作示例
视频介绍咸鱼之王后台挂机软件和 鼠标连点器 Python实现
下面的动图主要展示了该工具可以最小化到系统托盘并从系统托盘恢复的操作。 项目组织
使用PySide6/PyQT 构建的GUI工具组织架构如下所示
采用了MVC模型通过MVC模式的应用可以实现数据、用户界面和业务逻辑的解耦提高代码的可读性、可维护性和可测试性模型、视图和控制器各自担负不同的责任使代码更具结构化并允许团队成员分工合作独立开发和测试各个组件。
GameAssistant/
├── controllers/
│ ├── __init__.py
│ └── controller_main.py
├── make/
│ └── 辅助小工具.spec
├── models/
│ ├── invoke_func/
│ │ ├── __init__.py
│ │ ├── mouse_click.py
│ │ └── window_operate.py
│ ├── __init__.py
│ └── model_main.py
├── views/
│ ├── resources/
│ │ ├── main.ui
│ │ ├── trash.png
│ │ └── utils.qrc
│ ├── ui/
│ │ ├── __init__.py
│ │ ├── main_ui.py
│ │ └── utils_rc.py
│ ├── widgets/
│ │ ├── __init__.py
│ │ └── view_main.py
│ └── __init__.py
├── main.py
├── README.md
└── requirements.txt绘制GUI界面
在designer.exe 软件中绘制出下图所示的工具界面路径在views/resources/main.ui
使用了QTabWidget 控件绘制了两个页面。 在鼠标连击 页面有一个输入框在后台挂机 页面有一个输入框和两个按钮
这个比较简单动手拖拽需要的控件拼凑起来就可以了有手就行。
如下动图所示 model模型
这里使用了 QRunnable QThreadPool 实现的线程池并将所有任务都给到 线程池中运行。
鼠标点击 和 Windows操作 的代码放置在models/invoke_func/ 下
# -*- coding: utf-8 -*-
# Name: model_main.py
# Author: 小菜
# Date: 2023/6/14 20:00
# Description:from collections import defaultdict
from PySide6.QtCore import (QObject, QRunnable, QThreadPool, Signal)from models.invoke_func.mouse_click import click_mouse
from models.invoke_func.window_operate import (show_window, hide_window)flag Trueclass WorkerRunnable(QRunnable):def __init__(self, func, *args, **kwargs):super().__init__()self.func funcself.args argsself.status_signal kwargs.get(status_signal)def run(self):if not self.args:self.func()while flag:self.func(*self.args)def win_run(self):res self.func(*self.args)self.status_signal.emit({status: res})class ModelMain(QObject):win_status_signal: Signal Signal(dict)def __init__(self):super().__init__()self.thread_pool QThreadPool()self.thread_status_map defaultdict(bool)def stop_keyboard_listener(self):global flagif flag:flag Falsethread_name: str clickself.thread_status_map[thread_name] Falsedef click_operate(self, frequency: int 10):global flagthread_name: str clickif self.thread_status_map[thread_name]:returnflag Trueself.thread_status_map[thread_name] Trueif frequency 10:frequency 10print(flag, thread_name, self.thread_status_map[thread_name], frequency)click_frequency_map {10: [0.09],20: [0.035],30: [0.027],40: [0.014],50: [0.013],60: [0.005],70: [0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0],80: [0.01, 0.01, 0.01, 0],90: [0.01, 0.01, 0],100: [0.01, 0.0001, 0.0001, 0, 0],150: [0.001, 0.001, 0, 0, 0]}task WorkerRunnable(click_mouse,click_frequency_map.get(frequency, 150))self.thread_pool.start(task)def show_win_operate(self, title: str None):task WorkerRunnable(show_window,title,status_signalself.win_status_signal)self.thread_pool.start(task.win_run)def hide_win_operate(self, title: str None):task WorkerRunnable(hide_window,title,status_signalself.win_status_signal)self.thread_pool.start(task.win_run)
view视图
视图代码实现了
添加工具到系统托盘从系统托盘退出或恢复工具按下键盘的 Esc就最小化到系统托盘
# -*- coding: utf-8 -*-
# Name: view_main.py
# Author: 小菜
# Date: 2023/6/14 20:00
# Description:
import osfrom PySide6.QtGui import (QAction, QIcon, QShortcut, QKeySequence)
from PySide6.QtWidgets import (QMainWindow, QSystemTrayIcon, QMenu)from views import Ui_MainWindowclass ViewMain(QMainWindow, Ui_MainWindow):def __init__(self, parentNone) - None:super().__init__(parentparent)self.setupUi(self)# 创建系统托盘图标相关的变量和对象self._restore_action QAction()self._quit_action QAction()self._tray_icon_menu QMenu()# 创建系统托盘图标self.tray_icon QSystemTrayIcon(self)self.tray_icon.setIcon(QIcon(u:/trash.png))self.tray_icon.setToolTip(辅助小工具)# 创建系统托盘图标的菜单和动作self.create_actions()self.create_tray_icon()self.tray_icon.show()# 连接系统托盘图标的激活信号到槽函数self.tray_icon.activated.connect(self.tray_icon_activated)# 键盘监听self.listen_keyboard()def tray_icon_activated(self, reason):# 当系统托盘图标被激活时的操作if reason QSystemTrayIcon.ActivationReason.Trigger:self.restore_from_tray()def restore_from_tray(self):# 还原窗口if self.isMinimized():self.showNormal()elif self.isMaximized():self.showMaximized()else:self.show()def create_actions(self):# 创建系统托盘图标菜单的动作self._restore_action QAction(显示, self)self._restore_action.triggered.connect(self.restore_from_tray) # 显示菜单项触发还原窗口的操作self._quit_action QAction(退出, self)self._quit_action.triggered.connect(lambda: os._exit(0)) # 退出菜单项触发退出应用程序的操作def create_tray_icon(self):# 创建系统托盘图标的菜单self._tray_icon_menu QMenu(self)self._tray_icon_menu.addAction(self._restore_action)self._tray_icon_menu.addSeparator()self._tray_icon_menu.addAction(self._quit_action)self.tray_icon.setContextMenu(self._tray_icon_menu)self.tray_icon.show()def show_notification(self, title: str 连击信息⚠, text: str None, iconQSystemTrayIcon.MessageIcon.Information):# 显示系统通知self.tray_icon.showMessage(title,f警告{text},icon,2000)def listen_keyboard(self):# 键盘监听shortcut QShortcut(QKeySequence(Esc), self)# 当按下 Esc 键时隐藏窗口shortcut.activated.connect(self.hide)
controller控制器
这里做的操作是将 model与view连接起来充当了一个中间人的活儿。
# -*- coding: utf-8 -*-
# Name: controller_main.py
# Author: 小菜
# Date: 2023/6/14 20:00
# Description:import keyboard
from PySide6.QtCore import Slot
from PySide6.QtWidgets import QSystemTrayIconfrom views import ViewMain
from models import (ModelMain, WorkerRunnable)round_to_nearest_10 lambda number: min(round(number / 10) * 10, 150)class ControllerMain:def __init__(self):self.view ViewMain()self.model ModelMain()# 显示窗口self.view.show()# 初始化 键盘监听self.init_operate()# 绑定按钮self.view.btn_show_win.clicked.connect(self.show_win_operate)self.view.btn_hide_win.clicked.connect(self.hide_win_operate)# 绑定信号到槽函数self.model.win_status_signal.connect(self.window_listen)def init_operate(self):task WorkerRunnable(self.listen_keyboard)self.model.thread_pool.start(task)def listen_keyboard(self):keyboard.add_hotkey(CtrlShiftA, self.click_operate)keyboard.add_hotkey(CtrlShiftQ, self.model.stop_keyboard_listener)keyboard.wait()def click_operate(self):frequency 10# 创建匿名函数try:frequency round_to_nearest_10(int(self.view.line_edit_click.text()))print(frequency)except (ValueError, TypeError):...finally:self.model.click_operate(frequencyfrequency)self.view.show_notification(text开始点击)def show_win_operate(self):win_title self.view.line_edit_title.text()if not win_title:returnself.model.show_win_operate(titlewin_title)def hide_win_operate(self):win_title self.view.line_edit_title.text()if not win_title:returnself.model.hide_win_operate(titlewin_title)Slot(dict)def window_listen(self, item):if not item.get(status):self.view.show_notification(title警告警告⚠,text找不到窗口,iconQSystemTrayIcon.MessageIcon.Warning)
main函数
函数启动入口
# -*- coding: utf-8 -*-
# Name: main.py
# Author: 小菜
# Date: 2023/6/14 20:00
# Description:import sys
from ctypes import windllfrom PySide6.QtWidgets import QApplicationfrom controllers import ControllerMainif __name__ __main__:# 同步图标windll.shell32.SetCurrentProcessExplicitAppUserModelID(nothing)app QApplication()# 关闭窗口时候不退出程序app.setQuitOnLastWindowClosed(False)controller ControllerMain()# 事件循环sys.exit(app.exec())
总结
本文介绍了 PySide6/PyQT 打包游戏辅助工具的操作。
将前面介绍的 鼠标连点、Windows窗口操作等功能打包成一个GUI工具从更加方便后续的使用。
总而言之本文通过详细介绍使用 PySide6/PyQT 打包GUI的操作帮助读者理解和应用Python在游戏辅助工具开发中的打包功能。 文章转载自: http://www.morning.bswhr.cn.gov.cn.bswhr.cn http://www.morning.lwtld.cn.gov.cn.lwtld.cn http://www.morning.mdmxf.cn.gov.cn.mdmxf.cn http://www.morning.cttti.com.gov.cn.cttti.com http://www.morning.dwkfx.cn.gov.cn.dwkfx.cn http://www.morning.tlpgp.cn.gov.cn.tlpgp.cn http://www.morning.snnb.cn.gov.cn.snnb.cn http://www.morning.nqcts.cn.gov.cn.nqcts.cn http://www.morning.swdnr.cn.gov.cn.swdnr.cn http://www.morning.nlhcb.cn.gov.cn.nlhcb.cn http://www.morning.sdktr.com.gov.cn.sdktr.com http://www.morning.qcdtzk.cn.gov.cn.qcdtzk.cn http://www.morning.yhywr.cn.gov.cn.yhywr.cn http://www.morning.rrxmm.cn.gov.cn.rrxmm.cn http://www.morning.nkmw.cn.gov.cn.nkmw.cn http://www.morning.sgfnx.cn.gov.cn.sgfnx.cn http://www.morning.jfsbs.cn.gov.cn.jfsbs.cn http://www.morning.jrqcj.cn.gov.cn.jrqcj.cn http://www.morning.qzbwmf.cn.gov.cn.qzbwmf.cn http://www.morning.dwncg.cn.gov.cn.dwncg.cn http://www.morning.cgtrz.cn.gov.cn.cgtrz.cn http://www.morning.qpxrr.cn.gov.cn.qpxrr.cn http://www.morning.yxwrr.cn.gov.cn.yxwrr.cn http://www.morning.kbfzp.cn.gov.cn.kbfzp.cn http://www.morning.kjawz.cn.gov.cn.kjawz.cn http://www.morning.gxfzrb.com.gov.cn.gxfzrb.com http://www.morning.rkrl.cn.gov.cn.rkrl.cn http://www.morning.hqgxz.cn.gov.cn.hqgxz.cn http://www.morning.lbxcc.cn.gov.cn.lbxcc.cn http://www.morning.jrlgz.cn.gov.cn.jrlgz.cn http://www.morning.nfnxp.cn.gov.cn.nfnxp.cn http://www.morning.skmpj.cn.gov.cn.skmpj.cn http://www.morning.xhhqd.cn.gov.cn.xhhqd.cn http://www.morning.dzqyn.cn.gov.cn.dzqyn.cn http://www.morning.dtlqc.cn.gov.cn.dtlqc.cn http://www.morning.fxygn.cn.gov.cn.fxygn.cn http://www.morning.plydc.cn.gov.cn.plydc.cn http://www.morning.mttck.cn.gov.cn.mttck.cn http://www.morning.pxlsh.cn.gov.cn.pxlsh.cn http://www.morning.rrpsw.cn.gov.cn.rrpsw.cn http://www.morning.rrwgh.cn.gov.cn.rrwgh.cn http://www.morning.qbfs.cn.gov.cn.qbfs.cn http://www.morning.dkzwx.cn.gov.cn.dkzwx.cn http://www.morning.fjptn.cn.gov.cn.fjptn.cn http://www.morning.kxqwg.cn.gov.cn.kxqwg.cn http://www.morning.fppzc.cn.gov.cn.fppzc.cn http://www.morning.rkbly.cn.gov.cn.rkbly.cn http://www.morning.mmplj.cn.gov.cn.mmplj.cn http://www.morning.lhzqn.cn.gov.cn.lhzqn.cn http://www.morning.xtlty.cn.gov.cn.xtlty.cn http://www.morning.kcfnp.cn.gov.cn.kcfnp.cn http://www.morning.mkzdp.cn.gov.cn.mkzdp.cn http://www.morning.krzrg.cn.gov.cn.krzrg.cn http://www.morning.lgphx.cn.gov.cn.lgphx.cn http://www.morning.ssfq.cn.gov.cn.ssfq.cn http://www.morning.pfbx.cn.gov.cn.pfbx.cn http://www.morning.plqsz.cn.gov.cn.plqsz.cn http://www.morning.rqqkc.cn.gov.cn.rqqkc.cn http://www.morning.rxnl.cn.gov.cn.rxnl.cn http://www.morning.bmsqq.cn.gov.cn.bmsqq.cn http://www.morning.mlmwl.cn.gov.cn.mlmwl.cn http://www.morning.xscpq.cn.gov.cn.xscpq.cn http://www.morning.fnpyk.cn.gov.cn.fnpyk.cn http://www.morning.rgsgk.cn.gov.cn.rgsgk.cn http://www.morning.kfbth.cn.gov.cn.kfbth.cn http://www.morning.zqzhd.cn.gov.cn.zqzhd.cn http://www.morning.gjqgz.cn.gov.cn.gjqgz.cn http://www.morning.nkjjp.cn.gov.cn.nkjjp.cn http://www.morning.tntbs.cn.gov.cn.tntbs.cn http://www.morning.bqppr.cn.gov.cn.bqppr.cn http://www.morning.gcfg.cn.gov.cn.gcfg.cn http://www.morning.pwxkn.cn.gov.cn.pwxkn.cn http://www.morning.ffcsr.cn.gov.cn.ffcsr.cn http://www.morning.qbccg.cn.gov.cn.qbccg.cn http://www.morning.zrqs.cn.gov.cn.zrqs.cn http://www.morning.xwzsq.cn.gov.cn.xwzsq.cn http://www.morning.jhxdj.cn.gov.cn.jhxdj.cn http://www.morning.kgkph.cn.gov.cn.kgkph.cn http://www.morning.ktnmg.cn.gov.cn.ktnmg.cn http://www.morning.pybqq.cn.gov.cn.pybqq.cn