JoshMann15
JoshMann15

Reputation: 35

How do I use the Entry.get() function in tkinter?

I would like to make it so when you click confirm you get a message that says Thank you Username: and then what you entered for your username can someone plz help me with this.

from tkinter import *

root = Tk()

e1 = Entry(root)
e1.grid(row = 0, column = 1, pady = 2)
user = e1.get()

e2 = Entry(root)
e2.grid(row = 1, column = 1, pady = 2)

l1 = Label(root, text='Username:')
l1.grid(row = 0, column = 0, pady = 2)

l2 = Label(root, text='Password:')
l2.grid(row = 1, column = 0, pady = 2)

def confirm():
    l3 = Label(root, text='thank you')
    l3.grid(row = 2, column = 1, pady = 2)
    l4= Label(root, text='Your  Username: '+user)
    l4.grid(row  = 3, column = 1, pady =2)

b1 = Button(command=confirm, text='Confirm')
b1.grid(row = 3, column = 0, pady = 2)


root.mainloop()

Upvotes: 0

Views: 67

Answers (1)

Thomas
Thomas

Reputation: 1212

try:

from tkinter import *

root = Tk()
global e1
e1 = Entry(root)
e1.grid(row = 0, column = 1, pady = 2)


e2 = Entry(root)
e2.grid(row = 1, column = 1, pady = 2)

l1 = Label(root, text='Username:')
l1.grid(row = 0, column = 0, pady = 2)

l2 = Label(root, text='Password:')
l2.grid(row = 1, column = 0, pady = 2)

def confirm():
    user = e1.get()
    l3 = Label(root, text='thank you')
    l3.grid(row = 2, column = 1, pady = 2)
    l4= Label(root, text='Your  Username: '+user)
    l4.grid(row  = 3, column = 1, pady =2)

b1 = Button(command=confirm, text='Confirm')
b1.grid(row = 3, column = 0, pady = 2)

output:

output

Upvotes: 1

Related Questions