import tkinter as tk from tkinter import messagebox # 设置窗口居中 def window_info(): ws = window.winfo_screenwidth() hs = window.winfo_screenheight() x = (ws / 2) - 200 y = (hs / 2) - 200 print("%d,%d" % (ws, hs)) return x, y # 设置登陆窗口属性 window = tk.Tk() window.title('欢迎你登陆系统') a, b = window_info() window.geometry("450x300+%d+%d" % (a, b)) # 登陆界面的信息 tk.Label(window, text="欢迎你登陆系统", font=("宋体", 32)).place(x=80, y=50) tk.Label(window, text="账号:").place(x=120, y=150) tk.Label(window, text="密码:").place(x=120, y=190) # 显示输入框 var_usr_name = tk.StringVar() # 显示默认账号 var_usr_name.set('gisoracle') entry_usr_name = tk.Entry(window, textvariable=var_usr_name) entry_usr_name.place(x=190, y=150) var_usr_pwd = tk.StringVar() # 设置输入密码后显示*号 entry_usr_pwd = tk.Entry(window, textvariable=var_usr_pwd, show='*') entry_usr_pwd.place(x=190, y=190) # 登陆函数 def usr_login(): tk.messagebox.showinfo('Welcome', '您已经注册成功!') # 登陆和注册按钮 btn_login = tk.Button(window, text="登陆", command=usr_login) btn_login.place(x=170, y=230) btn_sign_up = tk.Button(window, text="注册", command=usr_login) btn_sign_up.place(x=270, y=230) window.mainloop()