且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Tkinter之输入框操作

更新时间:2022-09-05 22:39:22

昨天看好的,更新一下记录而已。

 

#coding: utf8
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"] = "login success."
    else:
        c["text"] = "user or password is wrong."
        e1.delete(0, t1)
        e2.delete(0, t2)

root = Tk()
root.wm_title("hello")


l1 = Label(root, text="username: ")
l1.grid(row=0, column=0, sticky=W)

e1 = Entry(root)
e1.grid(row=0, column=1, sticky=E)

l2 = Label(root, text="password: ")
l2.grid(row=1, column=0, sticky=W)

e2 = Entry(root)
e2['show'] = "*"
e2.grid(row=1, column=1, sticky=E)

b = Button(root, text="Login", command=reg)
b.grid(row=2, column=1, sticky=E)

c = Label(root, text="")
c.grid(row=3)

root.mainloop()

Tkinter之输入框操作