[Tkinter] loop function when called from tkinter button click - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: [Tkinter] loop function when called from tkinter button click (/thread-11509.html) |
loop function when called from tkinter button click - WantedStarling - Jul-12-2018 Hello, I have this code: #python 2.7.15 import pyautogui import time import msvcrt from threading import Thread import win32api import battle import Tkinter from Tkinter import * #launcher pos x:868 y:975 #rocket pos x:829 y:936 def click(): state = win32api.GetKeyState(0x01) if state: pyautogui.hotkey("ctrlleft") def PLD_8(): pyautogui.hotkey("2") root.after(500, PLT_3030) def PLT_3030(): root.after(100, pyautogui.hotkey("7")) root.after(20000, PLD_8) root = Tk() root.geometry("300x200") root.title("Bot options") root = Tkinter.Button(root, text = "Click me", command = click) root.pack() root.mainloop() """key = msvcrt.getche() if key == 'z': click() elif key == 'x': if __name__ == '__main__': Thread(target = click).start() Thread(target = battle.battle).start() Thread(target = rocket).start()"""How can I make the click function loop when I press the button inside the tkinter window? Now it only executes every time I press the button, I want it to press the button once and then It will loop until I stop the code. Thank you for your time RE: loop function when called from tkinter button click - nilamo - Jul-12-2018 Whatever PLD_8 and PLT_3030 are, they already loop each other forever. So to start the loop, call one of them.
RE: loop function when called from tkinter button click - WantedStarling - Jul-12-2018 PLD_8 and PLT-3030 are looping correctly, the problem is with the click() function which doesn't loop
RE: loop function when called from tkinter button click - nilamo - Jul-13-2018 So why not just do what you do in the other two functions? root.after(100, click)
RE: loop function when called from tkinter button click - WantedStarling - Jul-13-2018 I have already done it, it doesn't work. I don't get any error it just doesn't work. RE: loop function when called from tkinter button click - nilamo - Jul-13-2018 Put some debug prints in. See what state is. Maybe "doing nothing" is what it's supposed to do, because whatever you're checking isn't returning valid values?
|