[Python] I'm having trouble stopping a loop after N number of times this loop has been executed

Discussão em 'Python' iniciado por Stack, Janeiro 30, 2025.

  1. Stack

    Stack Membro Participativo

    I wanted to make an application that enters code from a file into the game, but I need to specify how many times new codes will be entered and I encountered the problem TypeError: 'int' object is not iterable

    import keyboard
    import tkinter as tkinter
    from tkinter import messagebox, Entry
    import tkinter as tk
    from time import sleep
    import pyautogui
    isClicking = False
    lim = 0
    window = tk.Tk()
    window.title("Auto Code")
    window.geometry('720x360')
    file = open('promo.txt', 'r')
    def ser():
    global lim
    lim = text.get()
    if lim != '':
    text.delete(0, 'end')
    else:
    tk.messagebox.showinfo("Error", ('Text Empty'))
    def tumb():
    global isClicking
    if isClicking:
    isClicking = False
    print('Off')
    else:
    isClicking = True
    print('On')
    if isClicking:
    for i in file and range(int(lim)):
    pyautogui.moveTo(1564, 1008)
    pyautogui.press('F6')
    sleep(0.3)
    pyautogui.press('F6')
    pyautogui.write(i)
    sleep(0.5)
    pyautogui.moveTo(838, 584)
    pyautogui.press('F6')
    sleep(0.2)
    pyautogui.press('F6')
    sleep(2)
    pyautogui.click(977, 733)
    pyautogui.press('F6')
    sleep(0.2)
    pyautogui.press('F6')
    sleep(1.5)

    text = tk.Entry(fg = "Black", width = 10)
    text.place(x = 220, y = 65)
    btn = tk.Button(window, text = "Add", command = ser, width = "40", height = "2", fg = "black", bg = "white")
    btn.place(x = 220, y =110)
    keyboard.add_hotkey('ctrl + v', tumb)
    window.mainloop()
    file.close()



    I tried to redo the loop but it continues to write text from the file

    Continue reading...

Compartilhe esta Página