用tkinter做一个登录界面
时间: 2024-01-30 22:02:48 浏览: 35
好的,下面是一个简单的登录界面的代码示例:
```python
import tkinter as tk
def login():
username = entry_username.get()
password = entry_password.get()
if username == "admin" and password == "123456":
label_result.config(text="登录成功")
else:
label_result.config(text="用户名或密码错误")
root = tk.Tk()
root.title("登录界面")
# 用户名标签和输入框
label_username = tk.Label(root, text="用户名:")
label_username.pack()
entry_username = tk.Entry(root)
entry_username.pack()
# 密码标签和输入框
label_password = tk.Label(root, text="密码:")
label_password.pack()
entry_password = tk.Entry(root, show="*")
entry_password.pack()
# 登录按钮
button_login = tk.Button(root, text="登录", command=login)
button_login.pack()
# 结果标签
label_result = tk.Label(root, text="")
label_result.pack()
root.mainloop()
```
运行以上代码,即可得到一个简单的登录界面。用户输入用户名和密码后,点击登录按钮,程序会判断用户名和密码是否正确,并在界面上显示结果。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)