Next TV
Next TV

Reputation: 31

Why is the module tk not callable?

I have a problem with my small login window. I'd like to program a small login window for one of my programs with a button to check the input. The program is working fine till my computer wants to enable the button:

TypeError: 'Tk' object is not callable

Why is this like that? What is wrong? Are all commands right?

    import tkinter
import os

def login():
    c= tkinter.Entry.get(input1)
    if c == "admin":
        a = tkinter.Entry.get(input2)
        if a == "1234":
            os.system('SpambotV1')
        else:
            print("hi")
    else:
        print("Cancled")


# Hauptprogramm

login=tkinter.Tk()
login.title("login")
login.config(background="blue")

photo = tkinter.PhotoImage(file="/Users/Hannes/Desktop/Spambot/Roboter.gif")
w = tkinter.Label(login,image=photo)
w.grid(row=0,column=1,padx=0,pady=0)

#Loginframe

frame1=tkinter.Frame(login)
frame1.grid(row=0,column=0,padx=5,pady=5)

#loginlabel

text1=tkinter.Label(frame1,text="Please login", bg="red")
text1.grid(row=0,column=0,padx=5,pady=5)

#Input1

input1=tkinter.Entry(frame1,width=12)
input1.grid(row=2,column=0,padx=5,pady=5)


#text 2
text2=tkinter.Label(frame1,text="Username",bg="red")
text2.grid(row=1,column=0,padx=5,pady=5)

#text 3
text3=tkinter.Label(frame1,text="Password",bg="red")
text3.grid(row=3,column=0,padx=5,pady=5)

#Entry 2

input2=tkinter.Entry(frame1,width=12)
input2.grid(row=4,column=0,padx=5,pady=5)

#knopf
knopf=tkinter.Button(frame1,text="Login",bg="red",command=login())
knopf.grid(row=4,column=0,padx=10,pady=10)

Upvotes: 0

Views: 412

Answers (1)

user7589150
user7589150

Reputation:

By creating a function called login and then creating a variable with the same name, you cause conflict in your code. Try renaming it to submit or something else. You specified the command of the button to be login() but python doesn't remember the login function, it only remembers the window variable you created, which is a Tk object, and that isn't callable. So what you should do is change the name of the login() function to submit().

Also remember to change:

knopf=tkinter.Button(frame1,text="Login",bg="red",command=login())

to:

knopf=tkinter.Button(frame1,text="Login",bg="red",command=submit)

and remove the brackets in as @PM 2Ring suggested EDIT: let's give some credit to @Rawing for spotting it too. Sorry. I didn't see the comment

Upvotes: 2

Related Questions