我如何使用get()函数

问题描述 投票:-1回答:1

我想这样做,所以当您单击确认时,您会收到一条消息,提示您感谢您的用户名:然后您输入的用户名可以帮助我解决这个问题。

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()

python
1个回答
0
投票

尝试:

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)
© www.soinside.com 2019 - 2024. All rights reserved.