一个简单的用tkinter编写的登录窗口

# -*- coding: utf-8 -*-

import os
import time
from tkinter_3D.journal import *
import tkinter as tk
from tkinter_3D.read_message import *
from tkinter import ttk
from PIL import Image, ImageTk
from tkinter import messagebox
from tkinter_3D.communal import center_window


def get_buttons():
    if user.get() == '123456' and pwd.get() == find()[0]:
        add_log(time.ctime() + ":登录成功")
        add_log(time.ctime() + ":访问主窗口")
        root.withdraw()
        import index

    elif user.get() == "" or user.get() == None:
        add_log(time.ctime() + ":用户名输入为空")
        messagebox.showinfo("提示", "请输入用户名!")
    elif pwd.get() == "" or pwd.get() == None:
        add_log(time.ctime() + ":密码输入为空")
        messagebox.showinfo("提示", "请输入密码!")
    else:
        add_log(time.ctime() + ":用户名或密码输入错误")
        messagebox.showerror("错误", "用户名或密码错误!")

add_log("")
add_log(time.ctime() + ":登录")
root = tk.Tk()
root.title("DR-Visual Guidance System")
root.config(bg='white')
root.wm_attributes('-topmost', 1)
filename = tk.PhotoImage(file=os.path.abspath('cgq.gif'))
tk.Label(root, image=filename, bg="white").pack()

frame1 = tk.Frame(root)
frame1.config(bg="white")
tk.Label(frame1, text="用户名:",font=("黑体", 14, 'bold'), bg="white").grid(row=0, column=0)
user = tk.Entry(frame1, bd=4, relief=tk.GROOVE)
user.grid(row=0, column=1)

tk.Label(frame1, text="  密码:", font=("黑体", 14, 'bold'), bg="white").grid(row=1, column=0,pady=10)

pwd = tk.Entry(frame1, bd=4, relief=tk.GROOVE,show="******")
pwd.grid(row=1, column=1)
if len(find()) > 4:
    tk.Label(frame1, text="密码已初始化",bg="white", fg="red", font=("仿宋", 8)).grid(row=2,column=0,columnspan=2,sticky='e')
frame1.pack(pady=10)

button = tk.Button(root, text='登录', command=get_buttons,
                   activebackground='Snow', bg='lightblue', fg="white", bd=4,
                   font=("黑体", 18, 'bold'))
button.pack(padx=10)

center_window(400, 340, root)
# 设置窗口是否可变长、宽,True:可变,False:不可变
root.resizable(width=tk.FALSE, height=tk.FALSE)
# 关闭标题栏
# root.overrideredirect(True)
root.mainloop()
os.system("pause")

刷新:

solve = frame5.after(1000, update_corrdinate)
solve = can.after(50, lambda : view_can(i+1, label))(带参函数)

停止刷新:

can.after_cancel(solve)

你可能感兴趣的:(python,tkinter)