Advertisement
Guest User

Untitled

a guest
Dec 13th, 2019
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.21 KB | None | 0 0
  1. from tkinter import *
  2. import tkinter as tk
  3. import tkinter.ttk as ttk
  4. from tkinter.ttk import Combobox
  5. import psycopg2
  6. import time
  7. from tkinter import messagebox as mb
  8. from PIL import Image
  9. from PIL import ImageTk
  10.  
  11.  
  12. con = psycopg2.connect(
  13. #данные
  14. )
  15.  
  16. TITLE = "Authentification"
  17.  
  18. WIDTH = 200
  19. HEIGHT = 200
  20.  
  21. # Classes and Utils functions
  22.  
  23.  
  24. root = tk.Tk()
  25. root.title(TITLE)
  26. root.geometry(str(WIDTH) + 'x' + str(HEIGHT))
  27. root.resizable(False, False)
  28. tries = 0
  29.  
  30.  
  31.  
  32.  
  33. # Programm functions and Event handlers
  34.  
  35. def page():
  36. label_login = tk.Label(root, text='Login:', )
  37. entry_login = tk.Entry(root)
  38.  
  39. label_password = tk.Label(root, text='Password:')
  40. entry_password = tk.Entry(root, show='*')
  41.  
  42. button_login = tk.Button(root, text='LogIn', command=lambda: log_in(entry_login, entry_password, button_login))
  43. button_signup = tk.Button(root, text='SignUp', command=lambda: signup(entry_login, entry_password))
  44.  
  45. label_login.place(x=10, y=10)
  46. entry_login.place(x=10, y=35)
  47. label_password.place(x=10, y=60)
  48. entry_password.place(x=10, y=85)
  49. button_login.place(x=10, y=115, width=50, height=25)
  50. button_signup.place(x=10, y=155, width=50, height=25)
  51.  
  52.  
  53. def log_in(entry_login, entry_password, button_login):
  54. global tries
  55. login1 = entry_login.get()
  56. password1 = entry_password.get()
  57.  
  58. cur = con.cursor()
  59. cur.execute(f"SELECT count(*) FROM users WHERE login = '{login1}' and password = '{password1}'")
  60. rows = cur.fetchall()
  61. print(rows)
  62.  
  63. if rows[0][0] == 1:
  64. start_page()
  65. if rows[0][0] == 0:
  66. tries += 1
  67. lbl_t = Label(root, text="Wrong login/password")
  68. lbl_t.place(x=60, y=115)
  69. print('wrong')
  70. print(tries)
  71. if tries >= 3:
  72. print('more 3 tries')
  73. button_login.place_forget()
  74. entry_login.place_forget()
  75. entry_password.place_forget()
  76. time.sleep(5)
  77. button_login.place(x=10, y=115, width=50, height=25)
  78. entry_login.place(x=10, y=35)
  79. entry_password.place(x=10, y=85)
  80. tries = 0
  81.  
  82. def start_page():
  83. root.iconify()
  84. top = Toplevel()
  85. top.wm_state('zoomed')
  86. menu = Menu(top)
  87. new_item = Menu(menu)
  88. new_item.add_command(label='exit', command=lambda: destroy(top))
  89. menu.add_cascade(label='menu', menu=new_item)
  90. top.config(menu=menu)
  91. tab_control = ttk.Notebook(top)
  92. t_textile = ttk.Frame(tab_control)
  93. t_ingridients = ttk.Frame(tab_control)
  94. t_products = ttk.Frame(tab_control)
  95. ################################################################################
  96. t_workshop = ttk.Frame(tab_control)
  97. tab_control.add(t_textile, text='Utensils')
  98. tab_control.add(t_ingridients, text='Ingridients')
  99. tab_control.add(t_products, text='Cake decoration')
  100. tab_control.add(t_workshop, text='Workshops')
  101. tab_control.pack(expand=1, fill='both')
  102.  
  103. # tab utensils
  104. tree_u = ttk.Treeview(t_textile, columns=('name', 'type', 'age', 'value'), show='headings', height=50)
  105. tree_u.column('name', width=100, anchor=tk.CENTER)
  106. tree_u.column('type', width=165, anchor=tk.CENTER)
  107. tree_u.column('age', width=150, anchor=tk.CENTER)
  108. tree_u.column('value', width=100, anchor=tk.CENTER)
  109. tree_u.heading('name', text='name')
  110. tree_u.heading('type', text='type')
  111. tree_u.heading('age', text='age')
  112. tree_u.heading('value', text='value')
  113. tree_u.pack()
  114. show = Button(t_textile, text="Show", command=lambda: show_utensils(tree_u))
  115. show.place(x=350, y=0)
  116.  
  117. # tab cake decoration
  118. tree = ttk.Treeview(t_products,columns=('art','name','ed.izm', 'value','shelf life','cost', 'supplier'),show='headings', height=50)
  119. tree.column('art', width=50, anchor=tk.CENTER)
  120. tree.column('name', width=100, anchor=tk.CENTER)
  121. tree.column('value', width=100, anchor=tk.CENTER)
  122. tree.column('ed.izm', width=100, anchor=tk.CENTER)
  123. tree.column('cost', width=60, anchor=tk.CENTER)
  124. tree.column('shelf life', width=100, anchor=tk.CENTER)
  125. tree.column('supplier', width=100, anchor=tk.CENTER)
  126. tree.heading('art', text='art')
  127. tree.heading('name', text='name')
  128. tree.heading('value', text='value')
  129. tree.heading('ed.izm', text='ed.izm')
  130. tree.heading('cost', text='cost')
  131. tree.heading('shelf life', text='shelf life')
  132. tree.heading('supplier', text='supplier')
  133. tree.pack()
  134.  
  135. show = Button(t_products, text="Show", command=lambda: show_records(tree))
  136. show.place(x=250, y=0)
  137. edit = Button(t_products, text="add", command=lambda: add_records(tree))
  138. edit.place(x=250, y=50)
  139. delete = Button(t_products, text="Del", command=lambda: del_records(tree))
  140. delete.place(x=250, y=100)
  141. interval = Button(t_products, text="interval of dates",command=lambda: interval_decor(tree))
  142. interval.place(x=250, y=150)
  143. # tab ingridients
  144. tree_i = ttk.Treeview(t_ingridients,
  145. columns=('name', 'value', 'delivery time', 'supplier', 'art', 'ed.izm', 'cost',),
  146. show='headings', height=50)
  147. tree_i.column('art', width=50, anchor=tk.CENTER)
  148. tree_i.column('name', width=100, anchor=tk.CENTER)
  149. tree_i.column('value', width=100, anchor=tk.CENTER)
  150. tree_i.column('ed.izm', width=100, anchor=tk.CENTER)
  151. tree_i.column('cost', width=60, anchor=tk.CENTER)
  152. tree_i.column('delivery time', width=100, anchor=tk.CENTER)
  153. tree_i.column('supplier', width=100, anchor=tk.CENTER)
  154. tree_i.heading('art', text='art')
  155. tree_i.heading('name', text='name')
  156. tree_i.heading('value', text='value')
  157. tree_i.heading('ed.izm', text='ed.izm')
  158. tree_i.heading('cost', text='cost')
  159. tree_i.heading('delivery time', text='delivery time')
  160. tree_i.heading('supplier', text='supplier')
  161. tree_i.pack()
  162. show = Button(t_ingridients, text="Show", command=lambda: show_ingridients(tree_i))
  163. show.place(x=250, y=0)
  164. edit = Button(t_ingridients, text="add", command=lambda: add_ingridients())
  165. edit.place(x=250, y=50)
  166. delete = Button(t_ingridients, text="Del", command=lambda: del_ingridients(tree_i))
  167. delete.place(x=250, y=100)
  168. interval = Button(t_ingridients, text="interval of dates", command=lambda: interval_ingridients(tree_i))
  169. interval.pack()
  170. ################################################################################
  171. #tab workshops
  172. labelTop = tk.Label(t_workshop,text = "Choose workshop:")
  173. labelTop.pack()
  174.  
  175. comboExample = ttk.Combobox(t_workshop, values=("Assembly", "Backing","Design","Packing","Production"))
  176. comboExample.pack()
  177. choosed = Button(t_workshop,text='Ok',command=lambda:current_workshop(comboExample,t_workshop))
  178. choosed.pack()
  179.  
  180. ################################################################################
  181. # defs
  182. def current_workshop(comboExample,t_workshop):
  183. shop = comboExample.get()
  184. if shop == 'Design':
  185. img = ImageTk.PhotoImage(Image.open("icons/FirstAid.png"))
  186. panel = Label(t_workshop, image=img)
  187. panel.pack(side="bottom", fill="both", expand="yes")
  188. print('suc')
  189.  
  190.  
  191. else:
  192. print('No')
  193.  
  194. def destroy(top):
  195. top.iconify()
  196. root.deiconify()
  197.  
  198.  
  199.  
  200.  
  201. start_page()
  202. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement