Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 [Tkinter] loop function when called from tkinter button click
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:

def PLD_8():
    root.after(500, PLT_3030)

def PLT_3030():
    root.after(100, pyautogui.hotkey("7"))
    root.after(20000, PLD_8)

root = Tk()
root.title("Bot options")
root = Tkinter.Button(root, text = "Click me", command = click)

"""key = msvcrt.getche()
if key == 'z':
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
Whatever PLD_8 and PLT_3030 are, they already loop each other forever. So to start the loop, call one of them.
PLD_8 and PLT-3030 are looping correctly, the problem is with the click() function which doesn't loop
So why not just do what you do in the other two functions? root.after(100, click)
I have already done it, it doesn't work. I don't get any error it just doesn't work.
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?

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  tkinter button not accessing the command when clicked jhf2 1 117 Nov-23-2019, 10:17 PM
Last Post: DT2000
  Tkinter button in for Simpsunt 3 104 Nov-23-2019, 01:41 AM
Last Post: Larz60+
  [Tkinter] Checking button click in Tkinter GalaxyCoyote 3 239 Oct-20-2019, 03:28 AM
Last Post: GalaxyCoyote
  Active tkinter text output during loop dvanommen 2 344 Oct-18-2019, 02:23 PM
Last Post: dvanommen
  [Tkinter] Tkinter button help and general commands Iceman 1 243 Sep-01-2019, 05:09 PM
Last Post: Yoriz
  [PyQt] Problem how to click a button inside a group box? mart79 2 251 Aug-05-2019, 01:21 PM
Last Post: mart79
  [PySimpleGui] How to alter mouse click button of a standard submit button? skyerosebud 3 414 Jul-21-2019, 06:02 PM
Last Post: FullOfHelp
  [Tkinter] Button won't execute function TheLegendOfPanda 2 357 Jul-05-2019, 07:41 PM
Last Post: TheLegendOfPanda
  TKinter GUI / Pandas Data frame Loop NSearch 0 861 Jun-26-2019, 12:37 AM
Last Post: NSearch
  [Tkinter] How make a button perform a function after the user inputs numbers Zephyrforce 1 371 May-22-2019, 05:43 PM
Last Post: woooee

Forum Jump:

Users browsing this thread: 1 Guest(s)