tkinter 登录界面
时间: 2023-08-04 09:06:07 浏览: 54
下面是一个简单的 Python Tkinter 登录界面的示例代码:
```
import tkinter as tk
root = tk.Tk()
root.title("Login")
label_user = tk.Label(root, text="Username")
label_user.grid(row=0, column=0)
entry_user = tk.Entry(root)
entry_user.grid(row=0, column=1)
label_password = tk.Label(root, text="Password")
label_password.grid(row=1, column=0)
entry_password = tk.Entry(root, show="*")
entry_password.grid(row=1, column=1)
def login():
username = entry_user.get()
password = entry_password.get()
if username == "admin" and password == "secret":
tk.messagebox.showinfo("Info", "Login successful")
else:
tk.messagebox.showerror("Error", "Incorrect username or password")
button_login = tk.Button(root, text="Login", command=login)
button_login.grid(row=2, column=1)
root.mainloop()
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.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)
![](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)