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] color change for hovering over button teacher 4 54 Yesterday, 06:33 AM
Last Post: teacher
  [Tkinter] updating tkinter chart from within function mikisDW 1 77 Jul-02-2020, 03:33 AM
Last Post: deanhystad
  tkinter button help Gina92 10 288 May-27-2020, 08:17 AM
Last Post: Gina92
  [PyQt] Loop triggered by button help Purple0 1 184 May-17-2020, 02:57 AM
Last Post: deanhystad
  How to make button text bold in Tkinter? scratchmyhead 2 181 May-16-2020, 02:53 AM
Last Post: scratchmyhead
  Closing window on button click not working kenwatts275 4 228 May-03-2020, 01:59 PM
Last Post: deanhystad
  [Tkinter] Binding Entry box to <Button-3> created in for loop iconit 5 256 Apr-22-2020, 05:47 AM
Last Post: iconit
  Passing arguments into function, tkinter nanok66 3 355 Apr-18-2020, 11:53 PM
Last Post: nanok66
  [Tkinter] Tkinter - I have problem after import varaible or function from aGUI to script johnjh 2 263 Apr-17-2020, 08:12 PM
Last Post: johnjh
  [Tkinter] Is it possible to automate button generation in tkinter? FirePepi 3 297 Apr-10-2020, 12:14 PM
Last Post: Riddle

Forum Jump:

Users browsing this thread: 1 Guest(s)