Advertisement
al33kappa

Untitled

Jun 12th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.76 KB | None | 0 0
  1. from tkinter import *
  2. from tkinter import messagebox
  3. root = Tk()
  4. root.geometry("800x600")
  5. lastrow = 0
  6. a = []
  7. matr = []
  8. massiv_intselect = []
  9. indeks_intselect = 0
  10. kolvo_yacheek = 0
  11. MyFile = "hello.txt"
  12. names = ["№","Наименование","Срок хранения","Страна","Цена","В наличии"]
  13. root.title("Продукты в магазине")
  14. intSelect = 0
  15. def defaultcells():
  16. global lastrow
  17. for i in range(6):
  18. b = Entry(root)
  19. b.grid(row=lastrow, column=i)
  20. a.append(b)
  21. lastrow += 1
  22. matr.append(a)
  23. matr[0][0].configure(width = 3)
  24. matr[0][1].configure(width=20)
  25. matr[0][2].configure(width=20)
  26. matr[0][3].configure(width=20)
  27. matr[0][4].configure(width=20)
  28. matr[0][5].configure(width=20)
  29. for i in range(6):
  30. matr[0][i].insert(END,names[i])
  31. matr[0][i].configure(readonlybackground='white',state='readonly')
  32. print(lastrow)
  33.  
  34. c = []
  35. b_mas = []
  36. k = []
  37. def addcells():
  38. global lastrow,intSelect,kolvo_yacheek,massiv_intselect,k
  39. if lastrow==13:
  40. btnAdd.configure(state=DISABLED)
  41. for i in range(6):
  42. if i==0:
  43. b = Button(root,text=str(lastrow),width=a[i]['width'],command = selectRow)
  44. b.grid(row=lastrow, column=i)
  45. k.append(b)
  46. # print("k[i]: " +k[i]indeks_intselect['text'])
  47. else:
  48. b = Entry(root,width = a[i]['width'],readonlybackground='white',state='readonly')
  49. b.grid(row=lastrow, column=i)
  50. c.append(b)
  51. intSelect += 1
  52. massiv_intselect.append(intSelect)
  53. for i in range(len(txt_list)):
  54. txt_list[i].configure(state='normal')
  55. txt_list[0].focus()
  56. txt_list[-1].configure(readonlybackground='white',state='readonly')
  57. b_mas.append(k)
  58. b_mas.append(c)
  59. lastrow += 1
  60. btnCopy.configure(state=NORMAL)
  61. btnAdd.configure(state=DISABLED)
  62. print("lastrow: " + str(lastrow))
  63. kolvo_yacheek+=1
  64. print("yacheiki: "+str(kolvo_yacheek))
  65. clearAll()
  66.  
  67. defaultcells()
  68. def selectRow():
  69. EnableAll()
  70. clearAll()
  71. asd = int(b_mas[0][0]['text'])*intSelect#разобраться почему работает и получать текст баттона
  72. print('SELECT: '+str(intSelect))
  73. print('ButtonTEXt: ' + str(asd))
  74. for i in range(5,0,-1):
  75. b_mas[1][asd-i].configure(state=NORMAL)
  76. txt_list[-i].insert(END,b_mas[1][intSelect-i].get())
  77. b_mas[1][asd- i].configure(readonlybackground='white',state='readonly')
  78.  
  79. disableAll()
  80.  
  81. def quit():
  82. root.destroy()
  83.  
  84. intS = 0
  85. intF = 1
  86.  
  87. def copy():
  88. global intF,txt_list,intS
  89. if (len(txt_list[0].get())==0 or len(txt_list[1].get())==0 or len(txt_list[2].get())==0 or len(txt_list[3].get())==0 or len(txt_list[4].get())==0):
  90. messagebox.showerror("Ошибка","Заполните все поля")
  91. else:
  92. for i in range(5):
  93. b_mas[intF][intS].configure(state=NORMAL)
  94. b_mas[intF][intS].insert(END,txt_list[i].get())
  95. b_mas[intF][intS].configure(readonlybackground='white',state='readonly')
  96. intS+=1
  97. btnAdd.configure(state=NORMAL)
  98. btnCopy.configure(state=DISABLED)
  99. clearAll()
  100. disableAll()
  101.  
  102. def EnableAll():
  103. for i in range(len(txt_list)):
  104. txt_list[i].delete(0, END)
  105. txt_list[i].configure(readonlybackground='white', state=NORMAL)
  106.  
  107. def clearAll():
  108. for i in range(len(txt_list)):
  109. txt_list[i].delete(0, END)
  110.  
  111. def disableAll():
  112. for i in range(len(txt_list)):
  113. txt_list[i].configure(readonlybackground='white',state='readonly')
  114. txt_list[-1].configure(disabledbackground = 'white',state=DISABLED)
  115.  
  116. def creation_of_file():
  117. global linesofFile,MyFile
  118. with open("hello.txt", "w") as hello_file:
  119. for i in range(len(names)):
  120. print(names[i] +": ", file=hello_file)
  121. linesofFile = MyFile.readlines()
  122.  
  123. def save_file():
  124. global linesofFile, MyFile
  125. with open("hello.txt", "a") as hello_file:
  126.  
  127.  
  128. btnAdd = Button(text="Добавить",command = addcells,width = 10,font="Arial 12")
  129. btnAdd.place(x = 680,y=70)
  130. btnExit = Button(text="Выход",width=10,command = quit,font="Arial 12")
  131. btnExit.place(x=680,y=380)
  132. btnCopy = Button(text="Записать",width = 10,command = copy,font="Arial 12")
  133. btnCopy.place(x=680,y=110)
  134. btnCreate= Button(text="Создать",width= 10,font="Arial 12",command = creation_of_file)
  135. btnCreate.place(x=680,y=150)
  136. btnSave = Button(text="Сохранить",width= 10,font="Arial 12",command = save_file)
  137. btnSave.place(x=680,y=190)
  138. "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"
  139. FamTxt= Entry()
  140. FamTxt.place(x=120,y=400)
  141. SrokTxt = Entry()
  142. SrokTxt.place(x=120,y=450)
  143. CountryTxt = Entry()
  144. CountryTxt.place(x=420,y=400)
  145. PriceTxt = Entry()
  146. PriceTxt.place(x=420,y=450)
  147. "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"
  148. lblFam = Label(text="Наименование: ",font="Arial 12")
  149. lblFam.place(x=0,y=395)
  150. lblSro = Label(text="Срок хранения: ", font = "Arial 12")
  151. lblSro.place(x=0,y=445)
  152. lblCountry = Label(text="Страна: ",font = "Arial 12")
  153. lblCountry.place(x=350,y=395)
  154. lblPrice = Label(text="Цена: ",font = "Arial 12")
  155. lblPrice.place(x=365,y=445)
  156. "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"
  157. myspinbox = Spinbox(values=("Имеется","Не имеется"))
  158. txt_list = [FamTxt,SrokTxt,CountryTxt,PriceTxt,myspinbox]
  159. myspinbox.place(x=350,y=500)
  160. disableAll()
  161. btnCopy.configure(state=DISABLED)
  162. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement