Я пытаюсь сделать запись в Tkinter, где я могу изменить значение root.after задержки, но я получаю ошибку, которую я не совсем понимаю. Я довольно плохо знаком с Python и особенно с классами, поэтому я не знаю, в чем проблема.
Traceback (most recent call last):
File "C:\Users\Kasper Holm\OneDrive\Python\workBot.py", line 52, in <module>
window = Bot(root) # makes passes window to the 'master' argument of the class 'Bot'.
File "C:\Users\Kasper Holm\OneDrive\Python\workBot.py", line 26, in __init__
self.root.after(self.timeAmount, self.running)
File "C:\Users\Kasper Holm\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 757, in after
return self.tk.call('after', ms, name)
_tkinter.TclError: bad argument "PY_VAR1": must be cancel, idle, info, or an integer
Это ошибка, которую она мне дает, и вот мой код.
import pyautogui as pag
from tkinter import *
class Bot:
def __init__(self, master):
self.statusVar = StringVar()
self.timeAmount = IntVar()
self.timeAmount.set(2000) # this sets the default amount of time between actions
statusLabel = Label(master, textvariable=self.statusVar).grid(row=0, column=1)
botStart = Button(master, text='Start', command=self.start_bot).grid(row=1, column=1)
botStop = Button(master, text='Stop', command=self.stop_bot).grid(row=2, column=1)
timeEntry = Entry(master)
timeEntry.grid(row=1, column=2) # time between actions (not done yet)
timeButton = Button(master, text='Set delay', command=self.timeAmount.set(timeEntry.get()))
timeButton.grid(row=0, column=2)
self.root = master
self.active = False
self.root.after(self.timeAmount, self.running)
def running(self):
if self.active:
# pag.moveTo(2715, 450) # moves the mouse to the bot-commands channel and clicks.
# pag.click(3006, 988) # moves the mouse to the chat bar.
# pag.typewrite('.work')
# pag.typewrite(['enter']) # typing enter this way will press the enter button instead of typing enter.
print(pag.position())
self.root.after(self.timeAmount, self.running)
def start_bot(self): # method for starting the bot.
self.active = True
self.statusVar.set('Started')
def stop_bot(self): # method for stopping the bot.
self.active = False
self.statusVar.set('Stopped')
root = Tk()
root.geometry('250x200')
root.title('Gamble bot')
root.attributes("-topmost", True) # makes sure the window is always on top.
window = Bot(root) # makes passes window to the 'master' argument of the class 'Bot'.
root.mainloop()