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


Messages In This Thread
loop function when called from tkinter button click - by WantedStarling - Jul-12-2018, 03:34 PM
RE: loop function when called from tkinter button click - by WantedStarling - Jul-12-2018, 10:42 PM
RE: loop function when called from tkinter button click - by WantedStarling - Jul-13-2018, 06:05 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] TKinter Remove Button Frame Nu2Python 8 1,007 Jan-16-2024, 06:44 PM
Last Post: rob101
  tkinter - touchscreen, push the button like click the mouse John64 5 865 Jan-06-2024, 03:45 PM
Last Post: deanhystad
  Using Tkinter inside function not working Ensaimadeta 5 5,067 Dec-03-2023, 01:50 PM
Last Post: deanhystad
  [Tkinter] Help running a loop inside a tkinter frame Konstantin23 3 1,581 Aug-10-2023, 11:41 AM
Last Post: Konstantin23
  Centering and adding a push button to a grid window, TKinter Edward_ 15 4,853 May-25-2023, 07:37 PM
Last Post: deanhystad
  Figure Gets Larger Every time I click a show button joshuagreineder 2 1,331 Aug-11-2022, 06:25 AM
Last Post: chinky
  Tkinter won't run my simple function AthertonH 6 3,883 May-03-2022, 02:33 PM
Last Post: deanhystad
  Can't get tkinter button to change color based on changes in data dford 4 3,436 Feb-13-2022, 01:57 PM
Last Post: dford
  [Tkinter] tkinter best way to pass parameters to a function Pedroski55 3 4,882 Nov-17-2021, 03:21 AM
Last Post: deanhystad
  Creating a function interrupt button tkinter AnotherSam 2 5,554 Oct-07-2021, 02:56 PM
Last Post: AnotherSam

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020