Python Tkinter 简单登录界面的实现
程序员文章站
2023-12-03 21:28:28
如下所示:
from tkinter import *
class reg (frame):
def __init__(self,master):...
如下所示:
from tkinter import * class reg (frame): def __init__(self,master): frame = frame(master) frame.pack() self.lab1 = label(frame,text = "账户:") self.lab1.grid(row = 0,column = 0,sticky = w) self.ent1 = entry(frame) self.ent1.grid(row = 0,column = 1,sticky = w) self.lab2 = label(frame,text = "密码:") self.lab2.grid(row = 1,column = 0) self.ent2 = entry(frame,show = "*") self.ent2.grid(row = 1,column = 1,sticky = w) self.button = button(frame,text = "登录",command = self.submit) self.button.grid(row = 2,column = 1,sticky = e) self.lab3 = label(frame,text = "") self.lab3.grid(row = 3,column = 0,sticky = w) self.button2 = button(frame,text = "退出",command = frame.quit) self.button2.grid(row = 3,column = 3,sticky = e) def submit(self): s1 = self.ent1.get() s2 = self.ent2.get() if s1 == 'admin' and s2 == '123': self.lab3["text"] = "登陆成功" else: self.lab3["text"] = "用户名或密码错误!" self.ent1.delete(0,len(s1)) self.ent2.delete(0,len(s2)) root = tk() root.title("用户登录") app = reg(root) root.mainloop()
以上这篇python tkinter 简单登录界面的实现就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。