Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在python程序中为函数设置开/关开关?_Python_Python 3.x_Tkinter - Fatal编程技术网

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

如何在python程序中为函数设置开/关开关?,python,python-3.x,tkinter,Python,Python 3.x,Tkinter,所以我有一个用于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 th

所以我有一个用于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\u cancel方法仅采用after变量名。 也许还要记住,您可以将root.update和root.update_idletasks与while循环一起使用,但这也不是很有效

希望这有助于你更好地理解,如果有任何疑问或错误,一定要让我知道


干杯

请分享您迄今为止所做的努力。@Jean MarcVolle老实说,不多,但我已经尽了最大的努力,想出了很多想法,但我想不出任何东西!我甚至在python服务器上询问了discord,但是在循环冻结GUI时,没有人能够帮助我?您可以使用root.after和root.after\u cancel完全停止函数。你们想要一个演示答案吗?@CoolCloud我太笨了,很久以来我一直试图让它工作,但它一直冻结!如果你能给我一个root.after和root.after的例子,我会非常感谢你的快速响应,但是,我使用了复选框,当它被选中时函数运行,当它不是时函数不运行。。。有什么想法吗?@SDG8-hmmmm,让我想想,请稍候。我真的非常感谢您帮助我入门,所以请花点时间,可能有一个小问题,您给我的代码只适用于一个函数,但在我的情况下,我有几个函数,例如,当我打开esp时,当我打开其他东西时,其他东西不会work@SDG8实例也许你必须更新你的Q。我建议你问一个新的Q