"""
1、其他函数不常用,这里只说get函数,get函数使用的时候不需要任何参数,它的返回值就是该输入框的内容。
"""
from tkinter import *
def reg():
s1 = e1.get()
s2 = e2.get()
t1 = len(s1)
t2 = len(s2)
if s1 == "111" and s2 == "222":
c["text"] = "登录成功"
else:
c["text"] = "用户名或密码错误"
e1.delete(0,t1)
e2.delete(0,t2)
root = Tk()
lb1 = Label(root,text = "用户名: ")
lb1.grid(row = 0, column = 0,sticky = W)
e1 = Entry(root)
e1.grid(row = 0, column = 1,sticky = E)
lb2 = Label(root,text = "密 码: ")
lb2.grid(row = 1, column = 0,sticky = W)
# 设置它的 show 属性让它 变成一个密码框,即e[‘show’] = ‘*’就可以了。
e2 = Entry(root)
e2['show'] = '*'
e2.grid(row = 1, column = 1,sticky = E)
btn = Button(root,text = "登录",command= reg)
btn.grid(row = 2, column = 1,sticky = E)
c = Label(root,text = "")
c.grid(row = 3)
root.mainloop()
运行结果如下:
![](https://img2018.cnblogs.com/blog/1494277/201810/1494277-20181023135336714-1067250980.png)