python中tkinter模块创建用户登录窗口

tkinter 实现用户登录界面
本例主要演示如何使用 tkinter 创建应用程序创建窗口,以及文本框、按钮、简单消息框等组件的用法。
import Tkinter
import tkMessageBox

def login():
	name = entryName.get()
	pwd = entryPwd.get()
	if name == 'admin' and pwd == '123456':
		tkMessageBox.showinfo(title = 'Python tkinter',message = 'OK')
	else:
		tkMessageBox.showinfo('Python tkinter',message = 'Error')
		
def cancel():
	varName.set('')
	varPwd.set('')
	
root = Tkinter.Tk()
varName = Tkinter.StringVar(value = '')
varPwd = Tkinter.StringVar(value = '')
labelName = Tkinter.Label(root,text = 'User Name:',justify = Tkinter.RIGHT,width = 80)
labelName.place(x = 10,y = 5,width = 80,height = 20)
entryName = Tkinter.Entry(root,width = 80,textvariable = varName)
entryName.place(x = 100,y = 5,width = 80,height = 20)

labelPwd = Tkinter.Label(root,text = 'User Pwd:',justify = Tkinter.RIGHT,width = 80)
labelPwd.place(x = 10,y = 30,width = 80,height = 20)
entryPwd = Tkinter.Entry(root,show = '*',width = 80,textvariable = varPwd)
entryPwd.place(x = 100,y = 30,width = 80,height = 20)

buttonOk = Tkinter.Button(root,text = 'Login',command = login)
buttonOk.place(x = 30,y = 70,width =50,height = 20)
buttonCancel = Tkinter.Button(root,text = 'Cancel',command = cancel)
buttonCancel.place(x = 90,y = 70,width = 50,height = 20)



root.mainloop()	

你可能感兴趣的:(python)