You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Tkinter制作的GTA SA刷钱GUI点击按钮后崩溃问题求助

GTA:圣安地列斯刷钱菜单GUI崩溃与报错问题解决

问题描述

用Python和Tkinter制作了《GTA:圣安地列斯》的刷钱菜单,点击刷钱按钮后能成功修改金钱,但GUI会直接崩溃;尝试点击停止按钮时触发如下报错:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\####\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 1921, in __call__
    return self.func(*args)
  File "C:\Users\####\PycharmProjects\gtasa\main.py", line 17, in moneygive
    process.write(moneypointer, 99999999999)
  File "C:\Users\####\PycharmProjects\gtasa\venv\lib\site-packages\ReadWriteMemory\__init__.py", line 125, in write
    ctypes.windll.kernel32.WriteProcessMemory(self.handle, lp_base_address, lp_buffer,

问题根源

  • Tkinter是单线程框架,主事件循环负责处理所有GUI交互和界面更新。moneygive函数中的while 1死循环会完全阻塞主循环,导致GUI失去响应甚至崩溃。
  • 强制停止程序时,未完成的process.write操作被中断,触发系统级的内存写入异常。

解决方案

  1. 用threading模块将刷钱逻辑放到独立线程中,避免阻塞GUI主循环
  2. 增加全局变量控制线程启停,实现平滑的开始/停止操作
  3. 给刷钱循环添加延迟,减少不必要的资源占用

修改后的完整代码

from ReadWriteMemory import ReadWriteMemory
from tkinter import *
import threading
import time

rwm = ReadWriteMemory
process = rwm().get_process_by_name(process_name="gta-sa.exe")
process.open()

# Money
baseaddress = 0x1F0000 + 0x118FD8
moneypointer = process.get_pointer(baseaddress, offsets=[0xB8]) 

# 控制线程运行的全局变量
running = False

def moneygive():
    global running
    running = True
    while running:
        process.write(moneypointer, 999999999)
        time.sleep(0.1)  # 每0.1秒写入一次,减少资源占用

def stop_money():
    global running
    running = False

root = Tk()
root.title("GTA San Andreas Menu")
root.iconbitmap()
root.geometry("200x200")

# 开始刷钱按钮
start_btn = Button(root, text="无限刷钱!", padx=50, command=lambda: threading.Thread(target=moneygive, daemon=True).start())
start_btn.pack(pady=10)

# 停止刷钱按钮
stop_btn = Button(root, text="停止刷钱", padx=50, command=stop_money)
stop_btn.pack(pady=10)

root.mainloop()

关键说明

  • 使用threading.Thread创建守护线程运行刷钱逻辑,daemon=True确保程序退出时线程自动终止
  • 通过running全局变量控制循环启停,避免强制中断导致的写入异常
  • 添加time.sleep(0.1)降低写入频率,既保证刷钱效果,又减少对系统资源的消耗

内容的提问来源于stack exchange,提问作者Sten

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.17 23:45:40