How to make an on/off switch for a function in a python program?

SDG8

So I have this python program for CSGO hacks that has esp, aimbot, wallhacks and more! Lets take the triggerbot code for example...

#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)

Now I want to be able to give the user an option to turn it on and off via tkinter switch, but I am not able to figure out on how to make it turn off completely once it is turned on.

I have tried somethings which I don't want to as they were stupid and also I searched on google couldn't find much.

Please help!

Cool Cloud

Take a look at this example:

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() method takes two arguments mainly:

  • ms - time to be run the function
  • func - the function to run after the given ms is finished.
  • after_cancel() method takes the variable name of after() only.

Perhaps also keep in mind, you can use root.update() and root.update_idletasks() with while loops, but its not efficient either.

Hope this helped you understand better, do let me know if any doubts or errors.

Cheers

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related