Python+tkinter制作经典登录界面和点击事件
作者:松鼠爱吃饼干 时间:2022-12-04 03:32:25
前言
Tkinter(即 tk interface) 是 Python 标准 GUI 库,简称 “Tk”;从本质上来说,它是对 TCL/TK 工具包的一种 Python 接口封装。
Tkinter 是 Python 自带的标准库,因此无须另行安装,它支持跨平台运行,不仅可以在 Windows 平台上运行,还支持在 Linux 和 Mac 平台上运行。
Tkinter 编写的程序,也称为 GUI 程序,GUI (Graphical User Interface)指的是“图形用户界面”,它是计算机图形学(CG)的一门分支,主要研究如何在计算机中表示图形,以及利用计算机进行图形的计算、处理和显示等相关工作。
GUI 这一概念并非 Python 语言独有,它属于计算机科学技术领域中的一个概念,比如使用 C/C++ 语言开发的 Qt、GTK、Electron 等都属于 GUI 软件包
环境使用
Python 3.8
Pycharm
模块使用
tkinter
PIL
代码部分
导入模块
import tkinter as tk
import tkinter.messagebox
from PIL import Image, ImageTk
先做一个大小合适的窗口
root = tk.Tk()
root.title('软件登陆界面')
root.geometry('369x200+500+500')
root.mainloop()
账号密码输入框
# 用户登陆
tk.Label(root, text='用户登陆', font=('微软雅黑', 20)).grid(row=0, column=0, columnspan=10)
# 登陆账号
tk.Label(root, text='登陆账号:', font=('微软雅黑', 15)).grid(row=1, column=0, padx=10)
# 账号输入框
account_va = tk.StringVar()
tk.Entry(root, textvariable=account_va).grid(row=1, column=1, padx=5)
# 登陆密码
tk.Label(root, text='登陆密码:', font=('微软雅黑', 15)).grid(row=2, column=0, padx=10)
# 密码输入框
password_va = tk.StringVar()
tk.Entry(root, textvariable=password_va, show='*').grid(row=2, column=1, padx=5)
点击按钮
# 登陆账号
tk.Label(root, text='登陆账号:', font=('微软雅黑', 15)).grid(row=1, column=0, padx=10)
# 注册账号
tk.Button(root, text='忘记密码',font=('微软雅黑'), relief="flat").grid(row=2, column=2, padx=10)
# 登陆按钮
tk.Button(root, text='登陆', font=('微软雅黑'), bg='red', fg='white', width=10, relief="flat").grid(row=3, column=0, columnspan=10)
tk.Label(root, text='公共用户名:admin 登陆密码:123456', fg='gray').grid(row=4, column=0, columnspan=10, pady=15)
点击事件绑定
登录
def Land():
if account_va.get() == 'admin' and password_va.get() == '123456':
tkinter.messagebox.showinfo(title='温馨提示', message='哈哈哈哈哈, 骗你的, 怎么会把密码告诉你呢')
tkinter.messagebox.showinfo(title='温馨提示', message='你可以点击注册会员试试')
else:
tkinter.messagebox.showerror(title='警告', message='你的账号密码有问题, 也可以点击注册会员')
忘记密码
def ForgetPassword():
tkinter.messagebox.showerror(title='错误', message='你根本就没有密码, 你心里没数?')
注册
def RegisterAnAccount():
top = tk.Toplevel()
top.title("扫码添加")
top.geometry('640x750+500+500')
# 导入图片
image = Image.open('img.png')
tk_image = ImageTk.PhotoImage(image)
# 在标签里放入图片
tk.Label(top, image=tk_image).pack()
top.mainloop()
最后效果
来源:https://www.cnblogs.com/qshhl/p/16652899.html
标签:Python,tkinter,登录
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python实现简单日志记录库glog的使用
2023-01-07 23:14:40
python pandas 如何替换某列的一个值
2021-07-01 01:08:07
![](https://img.aspxhome.com/file/2023/7/72217_0s.jpg)
update.where无索引导致MySQL死锁问题解决
2024-01-28 01:21:25
![](https://img.aspxhome.com/file/2023/4/112894_0s.png)
超常用的PHP正则表达式收集整理
2024-05-03 15:35:57
查看修改MySQL表结构命令
2024-01-26 03:45:52
如何利用Python打开txt格式的文件
2022-06-01 02:08:36
![](https://img.aspxhome.com/file/2023/3/99103_0s.png)
bootstrap-table后端分页功能完整实例
2024-04-29 13:11:44
![](https://img.aspxhome.com/file/2023/9/132839_0s.png)
对python中arange()和linspace()的区别说明
2023-08-23 05:32:53
在vue中动态添加class类进行显示隐藏实例
2024-05-09 15:13:28
![](https://img.aspxhome.com/file/2023/7/126547_0s.jpg)
Pytorch十九种损失函数的使用详解
2021-07-19 22:23:07
![](https://img.aspxhome.com/file/2023/0/95130_0s.png)
关于Python包导入报错的问题总结
2021-02-05 18:13:46
![](https://img.aspxhome.com/file/2023/7/75257_0s.png)
Golang正整数指定规则排序算法问题分析
2023-07-12 09:12:03
浅谈Python实现Apriori算法介绍
2021-09-14 19:10:22
![](https://img.aspxhome.com/file/2023/9/115729_0s.png)
js正则表达式验证密码强度【推荐】
2024-04-29 13:39:30
![](https://img.aspxhome.com/file/2023/1/132601_0s.png)
Python3.5字符串常用操作实例详解
2023-08-31 00:25:53
![](https://img.aspxhome.com/file/2023/8/62608_0s.png)
MYSQL METADATA LOCK(MDL LOCK) 理论及加锁类型测试
2024-01-23 11:16:46
SQL-ORDER BY 多字段排序(升序、降序)
2024-01-28 05:25:55
python读取和保存图片5种方法对比
2022-05-27 23:54:32
Python Socket传输文件示例
2023-10-18 17:19:00
几款好用的前端开发编辑器推荐安利
2023-11-21 13:30:00
![](https://img.aspxhome.com/file/2023/6/71296_0s.png)