123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- from tkinter import *
- import app
- import time
- import sql
- import tkinter.messagebox
- class my_reg(Frame):
- def __init__(self, init_window_name):
- self.init_window_name = init_window_name
- self.user_var = app.user_var
- self.screen_width = self.user_var.screen_width
- self.screen_height = self.user_var.screen_height
- self.font_size_title = app.font_size_title
- self.font_size_text = app.font_size_text
- self.main_gui_init()
- self.title_canvas_init()
- self.button_canvas_init()
- self.user_frame_init()
- self.view_timeout = 180
- self.user_var.windows_idx = 'user'
- self.fun_timer()
- self.sqlclient = sql.sqlclient
- def Submit_exit(self):
- self.init_window_name.after_cancel(self.task_user)
- self.main_frame.destroy()
- app.my_gui(self.init_window_name)
- def Submit_enter(self):
- s1 = self.username.get()
- s2 = self.password.get()
- stat = False
- sqlstr = "SELECT name,password FROM user_tbl WHERE name=\'" + s1 + "\'"
- print(sqlstr)
- jsondict = {}
- while self.sqlclient.busy == True:
- time.sleep(0.01)
- result = self.sqlclient.sql_inquire_all(sqlstr)
- if (result != None):
- for row in result:
- if row[1] == s2:
- stat = True
- if stat == True:
- tkinter.messagebox.showinfo(title='提示', message='登录成功!')
- self.user_var.auth_stat = True
- self.user_var.auth_timeout = 24*3600
- self.init_window_name.after_cancel(self.task_user)
- self.main_frame.destroy()
- app.my_gui(self.init_window_name)
- else:
- tkinter.messagebox.showwarning(title='提示', message='用户名或密码错误!')
- def auth_exit(self):
- if self.user_var.auth_timeout > 0:
- self.user_var.auth_timeout = self.user_var.auth_timeout - 1
- def view_exit(self):
- if self.view_timeout > 0:
- self.view_timeout = self.view_timeout - 1
- else:
- self.user_var.last_windows_idx = 'param'
- self.init_window_name.after_cancel(self.task_user)
- self.main_frame.destroy()
- app.my_gui(self.init_window_name)
- def windows_update(self):
- currentTime = time.strftime('%Y/%m/%d %H:%M:%S', time.localtime(time.time()))
- self.timelabel.config(text=currentTime)
- self.auth_exit()
- self.init_window_name.update()
- self.fun_timer()
- self.view_exit()
- def fun_timer(self):
- self.task_user=self.init_window_name.after(1000, self.windows_update)
- def main_gui_init(self):
- self.main_frame = Frame(self.init_window_name, width=self.screen_width, height=self.screen_height)
- self.main_frame.pack()
- # 标题栏
- def title_canvas_init(self):
- self.title_canvas = Canvas(self.main_frame, width=self.screen_width - 20, height=35, bg='SeaGreen')
- self.mainlabel = Label(self.title_canvas, text="用户登录", fg='yellow', font=("宋体", self.font_size_title),
- bg='SeaGreen', anchor='w')
- self.mainlabel.place(x=20, y=5)
- self.timelabel = Label(self.title_canvas, text=time.strftime('%Y/%m/%d %H:%M:%S', time.localtime(time.time())),
- fg='yellow', font=("宋体", self.font_size_title), bg='SeaGreen', anchor='e')
- self.timelabel.place(x=self.title_canvas.winfo_reqwidth() - self.timelabel.winfo_reqwidth() - 20, y=5)
- self.title_canvas.create_line(self.mainlabel.winfo_reqwidth() / 2 + 20, 32, self.title_canvas.winfo_reqwidth() -
- self.timelabel.winfo_reqwidth() / 2 - 20, 32, fill='white')
- self.title_canvas.place(x=10, y=10)
- # 控制栏
- def button_canvas_init(self):
- self.button_canvas = Canvas(self.main_frame, width=self.screen_width - 20, height=40)
- self.enter_button = Button(self.button_canvas, text="确定", fg='white', bg='DeepSkyBlue', width=8,
- activebackground='white', activeforeground='DeepSkyBlue',
- font=("宋体", self.font_size_title, "bold"), command=self.Submit_enter)
- self.enter_button.place(x=self.button_canvas.winfo_reqwidth()/2-180, y=0)
- self.exit_button = Button(self.button_canvas, text="取消", fg='white', bg='DeepSkyBlue', width=8,
- activebackground='white', activeforeground='DeepSkyBlue',
- font=("宋体", self.font_size_title, "bold"), command=self.Submit_exit)
- self.exit_button.place(x=self.button_canvas.winfo_reqwidth()/2+20, y=0)
- self.button_canvas.place(x=10, y=self.screen_height - 60)
- # 输入栏
- def user_frame_init(self):
- self.order_frame = Frame(
- self.main_frame, width=self.screen_width - 20, relief=SUNKEN, borderwidth=2,
- height=self.screen_height - self.title_canvas.winfo_reqheight() - self.button_canvas.winfo_reqheight() - 35)
- self.userpass_frame = Frame(
- self.order_frame, width=500, height=300, relief=SUNKEN, borderwidth=2)
- self.usernametitle = Label(self.userpass_frame, text="用户名:", font=("宋体", 20), anchor='e')
- self.usernametitle.place(x=50, y=90)
- self.username = Entry(self.userpass_frame, width=30)
- self.username.place(x=200, y=100)
- self.passwordtitle = Label(self.userpass_frame, text="密码:", font=("宋体", 20), anchor='e')
- self.passwordtitle.place(x=50, y=190)
- self.password = Entry(self.userpass_frame, width=30, show="*")
- self.password.place(x=200, y=200)
- self.userpass_frame.place(x=self.order_frame.winfo_reqwidth() / 2 - 250,
- y=self.order_frame.winfo_reqheight() / 2 - 150)
- # 工单栏展示
- self.order_frame.place(x=12, y=self.title_canvas.winfo_reqheight() + 15)
|