赞
踩
from tkinter import *from tkinter.messagebox import *#创建窗口
root=Tk()
root.geometry("300x200")#标签组件
labelName=Label(root,text="User Name:",font=("Arial",10))
labelName.place(x=10,y=5,width=80,height=20)
varName=StringVar(root,value="")
EntryName=Entry(root,textvariable=varName)
EntryName.place(x=100,y=5,width=120,height=20)
labelPsd=Label(root,text="Pass Word:",font=("Arial",10))
labelPsd.place(x=10,y=50,width=80,height=20)
varPsd=StringVar(root,value="")
EntryPsd=Entry(root,textvariable=varPsd,show="*")
EntryPsd.place(x=100,y=50,width=120,height=20)#自动填写用户名和密码
filename=r"C:UsersZXLDesktoptest.txt"with open(filename) as fp:
name,psd=fp.read().strip().split()
varName.set(name)
varPsd.set(psd)#复选框
remberMe=IntVar(root,value=1) #选中时为1,未选中为0
checkRemberMe=Checkbutton(root,text="remberme",variable=remberMe,
onvalue=1,offvalue=0,font=("Arial",11))
checkRemberMe.place(x=50,y=85)#登陆事件函数def login():
name=EntryName.get()
psd=EntryPsd.get()if name=="admin" and psd=="123456":
showinfo(title="恭喜",message="登陆成功")else:
showwarning(title="警告",message="用户名或密码错误")
btnOk=Button(root,text="login",command=login,font=("Arial",10))
btnOk.place(x=50,y=120,width=60,height=30)#取消函数def cancel():
varName.set("")
varPsd.set("")
btnCancel=Button(root,text="Cancel",command=cancel,font=("Arial",10))
btnCancel.place(x=150,y=120,width=60,height=30)
root.mainloop()
效果图如下:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。