Not a Class - TypeError: function() takes 0 positional arguments but 1 was given [duplicate]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Not a Class - TypeError: function() takes 0 positional arguments but 1 was given [duplicate]



This question already has an answer here:



I've already read several postingss on Stackoverflow about this error and the questions related to it: so this function is not a class method, there's not duplicated in the script, etc. It's a tkinter even-driven function. I saw a similar one on another posting, I tried it and it worked, but mine doesn't, and I can't figure why.

If you have nothing helpful to say, please refrain from making wise remarks, otherwise thanks in advance for the help.



For clarity, I reduced the context to its bare bones:


from tkinter import *

w = Tk()

def initializeVars():
global extRequired, Keyword, filePath
## extRequired = text1.get()
## Keyword = text2.get()
## filePath=BaseDir+AllFiles
print('initializing variables')

def func(event):
print("You hit return.")
w.bind('<Return>',initializeVars)

# Buttons
Button(text='Select Folder', command=initializeVars).grid(row=10,column=2)

w.mainloop()



As you can see I'm trying to bind initializeVars function to the return key of the keybaord.


initializeVars



This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.





This should solve your problem, yes? TypeError: printName1() takes 0 positional arguments but 1 was given
– Aran-Fey
Aug 11 at 23:11




1 Answer
1


w.bind('<Return>', initializeVars)



Event bindings expect a function that takes an event argument as the first parameter. So while you use the initializeVars correctly as a button handler, you need to accept the event parameter for the bind to work.


event


initializeVars


event


bind



If you don’t need the event, you can also make it optional:


def initializeVars(event = None):
# ...
print('initializing variables')





thank you much for the very useful help.
– Bert_AT
Aug 11 at 23:48

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS