Python20-01_GUI编程----登录界面设计和功能实现

登录界面设计和功能实现

Entry单行文本框

Entry用来接收一行单行字符串控件, 如果用户输入的长度长于Entry控件的长度时, 文字会自动向后滚动, 如果想输入多行文本, 则需要多行控件

 1 # coding:utf-8
 2 from tkinter import *
 3 from tkinter import messagebox
 4 
 5 
 6 class Application(Frame):
 7     """一个经典的GUI程序类写法"""
 8     def __init__(self, master=None):
 9         super().__init__(master)          # super代表的是父类的定义,而不是父类的对象
10         self.master = master
11         self.pack()
12         self.createWidget()
13 
14     def createWidget(self):
15         """创建登录界面组件"""
16         self.label01 = Label(self, text='用户名')
17         self.label01.pack()
18         # StringVar变量绑定到指定组件
19         # StringVar变量的值发生变化,组件内容也发生变化
20         # 组件内容发生变化, 变量的值也发生变化
21         v1 = StringVar()
22         self.entry01 = Entry(self, textvariable=v1)
23         self.entry01.pack()
24         v1.set('admin')
25         # 创建密码框
26         self.label02 = Label(self, text='密码')
27         self.label02.pack()
28         v2 = StringVar()
29         self.entry02 = Entry(self, textvariable=v2, show='*')
30         self.entry02.pack()
31         self.btn01 = Button(self, text='登录', command=self.login)
32         self.btn01.pack()
33 
34 
35 
36     def login(self):
37         username = self.entry01.get()
38         pwd = self.entry02.get()
39         if username == 'Liran' and pwd == '1314520':
40             messagebox.showinfo('命名系统', '登录成功!')
41         else:
42             messagebox.showinfo('命名系统', '登录失败')
43 
44 
45 if __name__ == "__main__":
46     root = Tk()
47     root.geometry("400x450+200+300")
48     root.title('测试')
49     app = Application(master=root)
50     root.mainloop()

Python20-01_GUI编程----登录界面设计和功能实现

 

上一篇:WPF之资源专题


下一篇:HBase平台 | 云Kafka搭配云HBase X-Pack构建一体化数据处理平台