user.py 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. from tkinter import *
  2. import app
  3. import time
  4. import sql
  5. import tkinter.messagebox
  6. class my_reg(Frame):
  7. def __init__(self, init_window_name):
  8. self.init_window_name = init_window_name
  9. self.user_var = app.user_var
  10. self.screen_width = self.user_var.screen_width
  11. self.screen_height = self.user_var.screen_height
  12. self.font_size_title = app.font_size_title
  13. self.font_size_text = app.font_size_text
  14. self.main_gui_init()
  15. self.title_canvas_init()
  16. self.button_canvas_init()
  17. self.user_frame_init()
  18. self.view_timeout = 180
  19. self.user_var.windows_idx = 'user'
  20. self.fun_timer()
  21. self.sqlclient = sql.sqlclient
  22. def Submit_exit(self):
  23. self.init_window_name.after_cancel(self.task_user)
  24. self.main_frame.destroy()
  25. app.my_gui(self.init_window_name)
  26. def Submit_enter(self):
  27. s1 = self.username.get()
  28. s2 = self.password.get()
  29. stat = False
  30. sqlstr = "SELECT name,password FROM user_tbl WHERE name=\'" + s1 + "\'"
  31. print(sqlstr)
  32. jsondict = {}
  33. while self.sqlclient.busy == True:
  34. time.sleep(0.01)
  35. result = self.sqlclient.sql_inquire_all(sqlstr)
  36. if (result != None):
  37. for row in result:
  38. if row[1] == s2:
  39. stat = True
  40. if stat == True:
  41. tkinter.messagebox.showinfo(title='提示', message='登录成功!')
  42. self.user_var.auth_stat = True
  43. self.user_var.auth_timeout = 24*3600
  44. self.init_window_name.after_cancel(self.task_user)
  45. self.main_frame.destroy()
  46. app.my_gui(self.init_window_name)
  47. else:
  48. tkinter.messagebox.showwarning(title='提示', message='用户名或密码错误!')
  49. def auth_exit(self):
  50. if self.user_var.auth_timeout > 0:
  51. self.user_var.auth_timeout = self.user_var.auth_timeout - 1
  52. def view_exit(self):
  53. if self.view_timeout > 0:
  54. self.view_timeout = self.view_timeout - 1
  55. else:
  56. self.user_var.last_windows_idx = 'param'
  57. self.init_window_name.after_cancel(self.task_user)
  58. self.main_frame.destroy()
  59. app.my_gui(self.init_window_name)
  60. def windows_update(self):
  61. currentTime = time.strftime('%Y/%m/%d %H:%M:%S', time.localtime(time.time()))
  62. self.timelabel.config(text=currentTime)
  63. self.auth_exit()
  64. self.init_window_name.update()
  65. self.fun_timer()
  66. self.view_exit()
  67. def fun_timer(self):
  68. self.task_user=self.init_window_name.after(1000, self.windows_update)
  69. def main_gui_init(self):
  70. self.main_frame = Frame(self.init_window_name, width=self.screen_width, height=self.screen_height)
  71. self.main_frame.pack()
  72. # 标题栏
  73. def title_canvas_init(self):
  74. self.title_canvas = Canvas(self.main_frame, width=self.screen_width - 20, height=35, bg='SeaGreen')
  75. self.mainlabel = Label(self.title_canvas, text="用户登录", fg='yellow', font=("宋体", self.font_size_title),
  76. bg='SeaGreen', anchor='w')
  77. self.mainlabel.place(x=20, y=5)
  78. self.timelabel = Label(self.title_canvas, text=time.strftime('%Y/%m/%d %H:%M:%S', time.localtime(time.time())),
  79. fg='yellow', font=("宋体", self.font_size_title), bg='SeaGreen', anchor='e')
  80. self.timelabel.place(x=self.title_canvas.winfo_reqwidth() - self.timelabel.winfo_reqwidth() - 20, y=5)
  81. self.title_canvas.create_line(self.mainlabel.winfo_reqwidth() / 2 + 20, 32, self.title_canvas.winfo_reqwidth() -
  82. self.timelabel.winfo_reqwidth() / 2 - 20, 32, fill='white')
  83. self.title_canvas.place(x=10, y=10)
  84. # 控制栏
  85. def button_canvas_init(self):
  86. self.button_canvas = Canvas(self.main_frame, width=self.screen_width - 20, height=40)
  87. self.enter_button = Button(self.button_canvas, text="确定", fg='white', bg='DeepSkyBlue', width=8,
  88. activebackground='white', activeforeground='DeepSkyBlue',
  89. font=("宋体", self.font_size_title, "bold"), command=self.Submit_enter)
  90. self.enter_button.place(x=self.button_canvas.winfo_reqwidth()/2-180, y=0)
  91. self.exit_button = Button(self.button_canvas, text="取消", fg='white', bg='DeepSkyBlue', width=8,
  92. activebackground='white', activeforeground='DeepSkyBlue',
  93. font=("宋体", self.font_size_title, "bold"), command=self.Submit_exit)
  94. self.exit_button.place(x=self.button_canvas.winfo_reqwidth()/2+20, y=0)
  95. self.button_canvas.place(x=10, y=self.screen_height - 60)
  96. # 输入栏
  97. def user_frame_init(self):
  98. self.order_frame = Frame(
  99. self.main_frame, width=self.screen_width - 20, relief=SUNKEN, borderwidth=2,
  100. height=self.screen_height - self.title_canvas.winfo_reqheight() - self.button_canvas.winfo_reqheight() - 35)
  101. self.userpass_frame = Frame(
  102. self.order_frame, width=500, height=300, relief=SUNKEN, borderwidth=2)
  103. self.usernametitle = Label(self.userpass_frame, text="用户名:", font=("宋体", 20), anchor='e')
  104. self.usernametitle.place(x=50, y=90)
  105. self.username = Entry(self.userpass_frame, width=30)
  106. self.username.place(x=200, y=100)
  107. self.passwordtitle = Label(self.userpass_frame, text="密码:", font=("宋体", 20), anchor='e')
  108. self.passwordtitle.place(x=50, y=190)
  109. self.password = Entry(self.userpass_frame, width=30, show="*")
  110. self.password.place(x=200, y=200)
  111. self.userpass_frame.place(x=self.order_frame.winfo_reqwidth() / 2 - 250,
  112. y=self.order_frame.winfo_reqheight() / 2 - 150)
  113. # 工单栏展示
  114. self.order_frame.place(x=12, y=self.title_canvas.winfo_reqheight() + 15)