eddie russell
eddie russell

Reputation: 1

Python can't assign function to call

i am doing a project in python in tkinter, to find out you age. in one line it says can't assign function to call. here is the line:

int(y_born_in) = Entry(window, width=20, bg="yellow", foreground = "purple",     font = "X-Files")   

( i got bored so i added fonts & stuff)

here is my actual code if you need it:

from tkinter import *
#key press function:
def click():
    output.delete(0.0, END)
    output.insert (2014 - int(y_born_in))
    output.insert ("\n or it could be")
    output.insert ( 2015 - int(y_born_in))
#code for the enter button
def enter_click(Event):
    output.delete(0.0, END)
    output.insert (2014 - int(y_born_in))
    output.insert ("\n or it could be")
    output.insert ( 2015 - int(y_born_in))


#collect text from text entry box
window = Tk()
window.title("how old are you?")
window.configure(background = "cyan")
#create label:
Label(window, text="please insert the year you were born", background = "hot pink",foreground = "light green", font = "X-Files") .grid( sticky=N)
#create text entry box
int(y_born_in) = Entry(window, width=20, bg="yellow", foreground = "purple", font = "X-Files")
y_born_in.grid(row=1, column=0,sticky=N)
#add a submit button
submit = Button(window, text="SUBMIT", width=6, command=click, background = "purple", fg = "yellow", font = "X-Files") .grid( sticky=N)

#create another label
Label(window, text="you were born in the year", background = "blue", foreground = "red", font = "X-Files") .grid( sticky=N)

#create text box
output = Text(window, width=75, height=8, wrap=WORD, background="coral", fg = "blue", font = "X-Files")
output.grid( sticky=N)

#enter key works as the button
window.bind("<Return>", enter_click )


window.mainloop()

Upvotes: 0

Views: 193

Answers (1)

Kevin
Kevin

Reputation: 76194

You can't call int on the left side of an assignment statement. Instead, just do:

y_born_in = Entry(window, width=20, bg="yellow", foreground = "purple",     font = "X-Files")   

If you're trying to tell the program, "y_born_in should be an Entry that only accepts digits for input", that's a bit trickier. See Interactively validating Entry widget content in tkinter or Adding validation to an Entry widget for details.


Additionally, everywhere that you're trying to do int(y_born_in) to get what the user typed (like in click or enter_click), you should instead be doing int(y_born_in.get()).

Upvotes: 2

Related Questions