Python Forum

Full Version: __call__() got an unexpected keyword argument 'text'
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
IDK what my problem is, i run it and i have come to this conclusion that if i get rid of the startClick function it runs if i put it back it breaks. plz help
Error:
Traceback (most recent call last): File "C:\Users\saba_\Desktop\python\clickerHero.py", line 44, in <module> start = Button(root, text="start", width=25, bg="lightgreen", command=startClick) TypeError: __call__() got an unexpected keyword argument 'text' >>>
from tkinter import *
import time
from pynput.mouse import Button, Controller

#creates the window
root = Tk()
root.geometry("600x400")
root.title("attempt1")


#global var




#def
def startClick():
    startClickingVar = 0
    if startClickingVar == 0:
        startClickingVar = 1
        while startClickingVar == 1:
            mouse.click(Button.right, 1)
    else:
        pass

def stopClick():
    if startClickingVar == 1:
        startClickingVar = 0
    else:
        pass

def exit():
    exit()

#var



#lables
welcomingLable = Label(root, text="Hi, Welocme to Hero Clicker AutoClicker", font=("arial", 20, "bold"), fg = "blue")
welcomingLable.pack(side=TOP)

#buttons
start = Button(root, text="start", width=25, bg="lightgreen", command=startClick)
start.place(x=50, y=140)

stop = Button(root,text="stop", width = 25, bg="red", command=stopClick)
stop.place(x=300, y=140)

exitButton = Button(root, text="Exit", width = 25, bg="red", command=exit)
exitButton.place(x=175, y=180)


#enterys
numberOfClicks = 1
enterCardInfo = Entry(root, textvariable= numberOfClicks, width=50, bg="orange",)
enterCardInfo.place(x=150, y=100)


# has to stay below so everthing runs within
root.mainloop()
(Apr-06-2018, 08:10 PM)saba_keon Wrote: [ -> ]from tkinter import *
from pynput.mouse import Button, Controller

Here's a great example of why from package import * is bad. Later in your code, you have this:
Quote:
start = Button(root, text="start", width=25, bg="lightgreen", command=startClick)
start.place(x=50, y=140)

Is start a tkinter.Button, or a pynput.mouse.Button? It's a pynput.mouse.Button, but you're using it like a tkinter button. pynput.mouse.Button doesn't understand what all those extra arguments are, which is why you're getting an error.

I'd suggest removing from tkinter import *, replacing it with import tkinter as tk, and then prefixing all your tkinter code with tk., so there's no ambiguity over what you want to be happening.
I changed it from tkinter import * to import tkinter as tk but now it give me this error

Traceback (most recent call last):
File "C:\Users\saba_\Desktop\python\clickerHero.py", line 7, in <module>
tk.root = Tk()
NameError: name 'Tk' is not defined
>>>
Where is Tk()? If it's in the tkinter package, then you need to prefix it. Try this, instead:
root = tk.Tk()
I got the code running but the two of the other buttons don't work. here is the error

Error:
Exception in Tkinter callback Traceback (most recent call last): File "C:\Users\saba_\AppData\Local\Programs\Python\Python36-32\lib\tkinter\__init__.py", line 1702, in __call__ return self.func(*args) File "C:\Users\saba_\Desktop\python\clickerHero.py", line 33, in stopClick if startClickingVar == 1: UnboundLocalError: local variable 'startClickingVar' referenced before assignment
and the exit button says this
Error:
Exception in Tkinter callback Traceback (most recent call last): File "C:\Users\saba_\AppData\Local\Programs\Python\Python36-32\lib\tkinter\__init__.py", line 1702, in __call__ return self.func(*args) File "C:\Users\saba_\Desktop\python\clickerHero.py", line 39, in exit exit() File "C:\Users\saba_\Desktop\python\clickerHero.py", line 39, in exit exit() File "C:\Users\saba_\Desktop\python\clickerHero.py", line 39, in exit exit() [Previous line repeated 985 more times] RecursionError: maximum recursion depth exceeded
Quote:
def exit():
    exit()
What do you think that's doing?
You defined a function, that calls itself. And when it runs, it calls itself. Again and again, forever.

For the other error, I'm not sure what line that is, since the lines are different now. But it kinda looks like this:
Quote:
def stopClick():
    if startClickingVar == 1:

A function is like a black box. You pass it arguments, it does something with them, then it hands you back a response. Your black box doesn't have any arguments, but it's trying to do something with something it doesn't have. Python is smart enough to look at the rest of the function to try to figure out what you're doing, and it's "helping" by letting you know that you defined the variable later on in the function, which means it's currently "unbound" (because it doesn't exist), but you eventually define it later (referenced before assignment): UnboundLocalError: local variable 'startClickingVar' referenced before assignment.

However, because you're using global variables, that doesn't actually help, either. Because you're not using it like a local variable, you're using a global. Python's error isn't going to help much with that, because it isn't something you should be doing, lol.

You have a comment, #global var. That would be the place to define your global startClickingVar. Then, in this function, the very first line should be a note to Python that it should go looking for the variable somewhere else, as that function doesn't need to define it:
def stopClick():
    global startClickingVar
    if startClickingVar == 1: