[英]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()
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:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.