如何在python程序中为函数设置开关



所以我有这个用于CSGO黑客的python程序,它有esp、aimbot、wallhacks等等!让我们以triggerbot代码为例。。。

#imports
import pymem
from pymem import process
import os
import sys
import time
import win32
from win32 import win32api
import win32process
import keyboard
import threading
from threading import Thread
import offsets
from offsets import *
def trigger():
while True:
localplayer = pm.read_int(client + dwLocalPlayer)
crosshairid = pm.read_int(localplayer + m_iCrosshairId)
getteam = pm.read_int(client + dwEntityList + (crosshairid - 1)*0x10)
localteam = pm.read_int(localplayer + m_iTeamNum)
crosshairteam = pm.read_int(getteam + m_iTeamNum)
if crosshairid>0 and crosshairid<32 and localteam != crosshairteam:
pm.write_int(client + dwForceAttack, 6)

现在我想通过tkinter开关给用户一个打开和关闭它的选项,但我不知道如何在打开后完全关闭它。

我尝试过一些我不想做的事情,因为他们很愚蠢,而且我在谷歌上搜索也找不到太多。

请帮忙!

看看这个例子:

from tkinter import *
root = Tk()
def run():
global rep
if var.get() == 1:
print('Hey')
rep = root.after(1000,run) #run the function every 2 second, if checked.
else:
root.after_cancel(rep) #cancel if the checkbutton is unchecked.
def step():
print('This is being printed in between the other loop')
var = IntVar()
b1 = Checkbutton(root,text='Loop',command=run,variable=var)
b1.pack()
b2 = Button(root,text='Seperate function',command=step)
b2.pack()
root.mainloop()

after()方法主要采用两个参数:

  • ms-运行函数的时间
  • func—在给定ms结束后运行的函数
  • after_cancel()方法只接受after((的变量名

也许还需要记住,您可以将root.update()root.update_idletasks()while循环一起使用,但这也不有效。

希望这能帮助你更好地理解,如果有任何疑问或错误,请告诉我。

干杯

最新更新