What alternative do I use to solve the problem of the get() function not working

Asked

Viewed 33 times

-1

from tkinter import *


def executar():
    l1['text'] = t1.get()
    l2['text'] = t2.get()
    l3['text'] = t3.get()


root = Tk()
root.title('App')

t1 = Entry(root)
t2 = Entry(root)
t3 = Entry(root)

l1 = Label(root)
l2 = Label(root)
l3 = Label(root)

b = Button(root, text='EXECUTAR', command='executar')

t1.grid()
t2.grid()
t3.grid()

l1.grid()
l2.grid()
l3.grid()

b.grid()

t1.focus()

root.mainloop()

1 answer

0

Your mistake there is that the argument command in creating the function should be the function itself. How you put 'executar'between quotes, this is a string containing the name of the function.

The Tkinter does not find the desired function from the name. Just change this line and put the function, without the parentheses (if you put the parentheses, the function is called at that point, and the return value of it is that it would be passed as argument).

I mean, just change that line:

 b = Button(root, text='EXECUTAR', command='executar')

to look like this:

 b = Button(root, text='EXECUTAR', command=executar)

And that’s it, your program works.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.