My kivy program is not working properly, "AssertionError: <Thread(Thread-1 (flood), initial)> is not callable"

Viewed 24

I started writing a spambot, it's not ready yet, but I noticed that it wasn't running. What's wrong with it? Before I put it the threading it was still working, so obviously there may be a problem there.

import time
import pyautogui
import os
import threading 
os.environ["KIVY_NO_CONSOLELOG"] = "1"

from kivy.config import Config
Config.set("graphics", "width", "400")
Config.set("graphics", "hight", "100")
Config.set("graphics", "resizable", "0")

from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.uix.textinput import TextInput


class asd(Widget):
    def __init__(self):
        super().__init__()
        start_button = Button(text="Start", size=(100, 50), pos=(0, 0))
        start_button.bind(on_press=threading.Thread(target=self.flood))
        start_button.start()
        self.add_widget(start_button)

        text_label = Label(text="Text", size=(100, 50), pos=(100, 300))
        self.add_widget(text_label)

        ammount_label = Label(text="Amount", size=(100, 50), pos=(100, 200))
        self.add_widget(ammount_label)

        delay_label = Label(text="Delay", size=(100, 50), pos=(100, 100))
        self.add_widget(delay_label)



    def flood(self, instance):
        time.sleep(5)
        for i in range(100):
            pyautogui.write("asd")
            pyautogui.press('enter')
            time.sleep(2)


class Spambot(App):
    def build(self):
        return asd()
        
Spambot().run()
1 Answers

The error message is explicit. Your code:

start_button.bind(on_press=threading.Thread(target=self.flood))

tries to set a Thread object as the callable for the bind, but a Thread is not callable (i.e., you cannot do Thread_instance()). One easy fix is to just assign a method as the callable for the bind, and in that method create and start the Thread.

Related