tkinter qq登录
时间: 2023-12-09 18:04:24 浏览: 82
以下是一个使用tkinter实现的QQ登录界面的例子:
```python
import tkinter as tk
import tkinter.messagebox
from PIL import Image, ImageTk
# 创建窗口
window = tk.Tk()
window.title('QQ登录')
window.geometry('400x300')
# 添加背景图片
canvas = tk.Canvas(window, width=400, height=135, bg='green')
image_file = Image.open('qq.png')
image = ImageTk.PhotoImage(image_file)
canvas.create_image(200, 0, anchor='n', image=image)
canvas.pack()
# 添加用户名和密码标签
tk.Label(window, text='用户名:').place(x=50, y=170)
tk.Label(window, text='密码:').place(x=50, y=210)
# 添加用户名和密码输入框
var_usr_name = tk.StringVar()
var_usr_name.set('example@python.com')
entry_usr_name = tk.Entry(window, textvariable=var_usr_name)
entry_usr_name.place(x=160, y=170)
var_usr_pwd = tk.StringVar()
entry_usr_pwd = tk.Entry(window, textvariable=var_usr_pwd, show='*')
entry_usr_pwd.place(x=160, y=210)
# 登录函数
def usr_login():
usr_name = var_usr_name.get()
usr_pwd = var_usr_pwd.get()
if usr_name == 'example@python.com' and usr_pwd == '123456':
tkinter.messagebox.showinfo(title='Welcome', message='登录成功!')
else:
tkinter.messagebox.showerror(message='用户名或密码错误!')
# 添加登录按钮
btn_login = tk.Button(window, text='登录', command=usr_login)
btn_login.place(x=170, y=240)
# 运行窗口
window.mainloop()
```
阅读全文