Advertisement
fevzi02

ПЗ - Коммунальные платежи

Oct 31st, 2021
1,175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 11.60 KB | None | 0 0
  1. from tkinter import *
  2. class CommunalPayments:
  3.     def __init__(self, tarif):
  4.         self.square = 75
  5.         self.tarif = tarif
  6.         self.counter = {"hotwater":[0,0], "coldwater":[0,0], "gas": [0,0], "heating": [0,0], "electricity":[0,0]}
  7.  
  8.     def setSquare(self, square):
  9.         self.square = square
  10.  
  11.     def setCounter(self, key, left='', right=''):
  12.         if left != '' and right != '':
  13.             self.counter[key] = left, right
  14.         elif right == '':
  15.             self.counter[key][0] = left
  16.         elif left != '':
  17.             self.counter[key][1] = right
  18.  
  19.     def hot_water(self):
  20.         return round((self.counter["hotwater"][1] - self.counter["hotwater"][0]) * self.tarif[0], 3)
  21.  
  22.     def cold_water(self):
  23.         return round((self.counter["coldwater"][1] - self.counter["coldwater"][0]) * self.tarif[1], 3)
  24.  
  25.     def gas(self):
  26.         return round((self.counter["gas"][1] - self.counter["gas"][0]) * self.tarif[2], 3)
  27.  
  28.     def heating(self):
  29.         by_area_apartment = self.counter["heating"][1] * self.square / 7000 * self.tarif[3]
  30.         heat_volume = self.counter["heating"][1] * (1 - 6000 / 7000) * self.square / 6000
  31.         return round(by_area_apartment + heat_volume * self.tarif[3], 3)
  32.         #https://otoplenie-doma.org/kak-rasschityvaetsya-otoplenie-v-kvartire.html
  33.  
  34.     def electricity(self):
  35.         return round((self.counter["electricity"][1] - self.counter["electricity"][0]) * self.tarif[4], 3)
  36.  
  37.     def summ(self):
  38.         return self.hot_water()+ self.cold_water() + self.gas() + self.heating() + self.electricity()
  39.  
  40.     spisok = [hot_water, cold_water, gas, heating, electricity]
  41.  
  42. class Grafic(CommunalPayments):
  43.     def __init__(self):
  44.         CommunalPayments.__init__(self, [205.15 , 39.28, 5.56151, 1400, 4.98])
  45.         self.button_number = 0
  46.         self.list_name =[ ["hotwater", "coldwater", "gas", "heating", "electricity"],
  47.             ["Горячая вода", "Холодная вода", "Газ", "Отопление", "Электроэнергия"] ]
  48.         self.root = Tk()
  49.         self.root.title("Коммунальные платежи")
  50.         self.u1_frame = Frame(self.root, width=800, height=80, bg ='#068888')
  51.         self.u1_frame.grid(row=0, column=0, padx=10, pady=5)
  52.         self.u2_frame = Frame(self.root, width=800, height=480, bg ='#068888')
  53.         self.u2_frame.grid(row=1, column=0, padx=10, pady=5)
  54.  
  55.         b_counter = Button(self.u1_frame, text='Ввести показания', command=self.b_left,
  56.                     bg='#ffffff', foreground='#000000', font = "Arial 20")
  57.         b_counter.place(x=150, y=40, anchor="c", height=40, width=270, bordermode=OUTSIDE)
  58.  
  59.         b_withdrawing_funds = Button(self.u1_frame, text='Посмотреть тариф и свои расходы', command=self.b_right,
  60.                     bg='#ffffff', foreground='#000000', font = "Arial 20")
  61.         b_withdrawing_funds.place(x=540, y=40, anchor="c", height=40, width=480, bordermode=OUTSIDE)
  62.  
  63.         self.b_left()
  64.         self.root.mainloop()
  65.     #___________________________________________________________________________
  66.     def is_digit(self, entry):
  67.         if entry.isdigit():
  68.            return True
  69.         else:
  70.             try:
  71.                 float(entry)
  72.                 return True
  73.             except ValueError:
  74.                 return False
  75.  
  76.     def renovation_U2(self):
  77.         self.button_number = 0
  78.         try:
  79.             self.u2_frame.destroy()
  80.         except:
  81.             pass
  82.  
  83.         self.u2_frame = Frame(self.root, width=800, height=480, bg ='#068888')
  84.         self.u2_frame.grid(row=1, column=0, padx=10, pady=5)
  85.  
  86.     def send(self):                            #b_left/which_button
  87.         key = self.list_name[0][self.button_number]
  88.         e_list = [self.is_digit(self.e1_send.get()), self.is_digit(self.e2_send.get()) , False]
  89.         try:
  90.             e_list[2] = self.is_digit(self.e3_send.get())
  91.         except:
  92.             pass
  93.         if e_list[0] == True and e_list[1] == True and e_list[2] == True:
  94.             entry_counter = "Изменены предыдущие и текущие показания и площадь"
  95.             font = "Arial 13"
  96.         elif e_list[0] == True and e_list[1] == True and e_list[2] == False:
  97.             entry_counter = "Изменены предыдущие и текущие показания"
  98.             font = "Arial 16"
  99.         elif e_list[0] == True and e_list[1] == False and e_list[2] == False:
  100.             entry_counter = "Изменены предыдущие показания"
  101.             font = "Arial 20"
  102.         elif e_list[0] == False and e_list[1] == True and e_list[2] == False:
  103.             entry_counter = "Изменены текущие показания"
  104.             font = "Arial 20"
  105.         elif e_list[0] == True and e_list[1] == False and e_list[2] == True:
  106.             entry_counter = "Изменены предыдущие показания и площадь"
  107.             font = "Arial 16"
  108.         elif e_list[0] == False and e_list[1] == True and e_list[2] == True:
  109.             entry_counter = "Изменены текущие показания и площадь"
  110.             font = "Arial 16"
  111.         elif e_list[0] == False and e_list[1] == False and e_list[2] == True:
  112.             entry_counter = "Изменена площадь"
  113.             font = "Arial 16"
  114.         elif e_list[0] == False and e_list[1] == False and e_list[2] == False:
  115.             entry_counter = "!ОШИБКА! Вы не ввели показания"
  116.             font = "Arial 19"
  117.  
  118.         if not e_list[0]:
  119.             e1_float = self.counter[key][0]
  120.         else:
  121.             e1_float = float(self.e1_send.get())
  122.         if not e_list[1]:
  123.             e2_float = self.counter[key][1]
  124.         else:
  125.             e2_float = float(self.e2_send.get())
  126.  
  127.         if e_list[2]:
  128.             e3_float = float(self.e3_send.get())
  129.             self.square = e3_float
  130.  
  131.         if e1_float <= e2_float:
  132.             self.setCounter(key, e1_float, e2_float)
  133.         else:
  134.             entry_counter = "!ОШИБКА! Предыдущие > Текущие "
  135.  
  136.         self.l_notification["text"] = entry_counter
  137.         self.l_notification["font"] = font
  138.  
  139.  
  140.  
  141.  
  142.     def which_button(self, i):       #b_left
  143.         self.root.title("Коммунальные платежи - Ввести показания - " + self.list_name[1][i])
  144.  
  145.         fg = "#9999"+str(i*2)[0]+str(i*3)[0]
  146.         if self.button_number != i:
  147.             try:
  148.                 self.l3_send.destroy()
  149.                 self.e3_send.destroy()
  150.             except:
  151.                 pass
  152.             self.b_send.destroy()
  153.  
  154.             self.b_send = Button(self.u2_frame, text='Отправить данные', command=self.send,
  155.                         bg='#ffffff', foreground='#000000', font = "Arial 20")
  156.             self.b_send.place(x=590, y=40*5+8, anchor="c", height=40, width=260, bordermode=OUTSIDE)
  157.  
  158.             self.l_notification["text"] = "Выбрано - " + self.list_name[1][i]
  159.             self.l_notification["font"] = "Arial 20"
  160.             self.l_notification["bg"] = "#9999"+str(i*2)[0]+str(i*3)[0]
  161.             if i == 3:
  162.                 self.l3_send = Label(self.u2_frame,text = "Введите площадь:", font = "Arial 20")
  163.                 self.l3_send.place(x=460, y=40*5+8, anchor="c", height=40, width=360)
  164.  
  165.                 self.e3_send = Entry(self.u2_frame, bg='#ffffff', foreground='#000000', justify='center', font = "Arial 18")
  166.                 self.e3_send.place(x=720, y=40*5+8, anchor="c", height=40, width=130, bordermode=OUTSIDE)
  167.  
  168.                 self.b_send.destroy()
  169.                 self.b_send = Button(self.u2_frame, text='Отправить данные', command=self.send,
  170.                             bg='#ffffff', foreground='#000000', font = "Arial 20")
  171.                 self.b_send.place(x=590, y=40*7+12, anchor="c", height=40, width=260, bordermode=OUTSIDE)
  172.         self.button_number = i
  173.  
  174.     def b_left(self):                                                           #НАЧАЛО
  175.         self.renovation_U2()
  176.         self.root.title("Коммунальные платежи - Ввести показания - " + self.list_name[1][0])
  177.  
  178.         for i in range(5):
  179.             fg = "#9999"+str(i*2)[0]+str(i*3)[0]
  180.             Button(self.u2_frame, text=self.list_name[1][i], command=lambda id=i: self.which_button(id),
  181.                         bg=fg, foreground='#000000',
  182.                         font = "Arial 20").place(x=140, y=40*(i+1)+2*i, anchor="c",
  183.                         height=40, width=250, bordermode=OUTSIDE)
  184.  
  185.         l1_send = Label(self.u2_frame,text = "Предыдущие показания:", font = "Arial 20")
  186.         l1_send.place(x=460, y=40, anchor="c", height=40, width=360)
  187.  
  188.         self.e1_send = Entry(self.u2_frame, bg='#ffffff', foreground='#000000', justify='center', font = "Arial 18")
  189.         self.e1_send.place(x=720, y=40, anchor="c", height=40, width=130, bordermode=OUTSIDE)
  190.  
  191.         l2_send = Label(self.u2_frame,text = "Новые показания:", font = "Arial 20")
  192.         l2_send.place(x=460, y=40*3+2, anchor="c", height=40, width=360)
  193.  
  194.         self.e2_send = Entry(self.u2_frame, bg='#ffffff', foreground='#000000', justify='center', font = "Arial 18")
  195.         self.e2_send.place(x=720, y=40*3+2, anchor="c", height=40, width=130, bordermode=OUTSIDE)
  196.  
  197.         self.b_send = Button(self.u2_frame, text='Отправить данные', command=self.send,
  198.                     bg='#ffffff', foreground='#000000', font = "Arial 20")
  199.         self.b_send.place(x=590, y=40*5+8, anchor="c", height=40, width=260, bordermode=OUTSIDE)
  200.  
  201.         self.l_notification = Label(self.u2_frame,text = "По умолчанию - Горячая вода",bg = "#00FF00", font = "Arial 20")
  202.         self.l_notification.place(x=400, y=40*9+14, anchor="c", height=50, width=460)
  203.  
  204.  
  205.     def b_right(self):                                                          #НАЧАЛО
  206.         self.renovation_U2()
  207.         self.root.title("Коммунальные платежи - Посмотреть тариф и свои расходы")
  208.         Label(self.u2_frame,text = "Услуга",bg = "#00FF00",
  209.             font = "Arial 20").place(x=134, y=25, anchor="c", height=40, width=260)
  210.         Label(self.u2_frame,text = "Тариф",bg = "#00FF00",
  211.             font = "Arial 20").place(x=135+270-4, y=25, anchor="c", height=40, width=260)
  212.         Label(self.u2_frame,text = "Расходы",bg = "#00FF00",
  213.             font = "Arial 20").place(x=130+270*2-2, y=25, anchor="c", height=40, width=260)
  214.  
  215.         for i in range(5):
  216.             fg = "#9999"+str(i*2)[0]+str(i*3)[0]
  217.             Label(self.u2_frame,text = self.list_name[1][i],bg = fg,
  218.             font = "Arial 20").place(x=134, y=80+50*i+3*i, anchor="c", height=40, width=260)
  219.  
  220.         for i in range(5):
  221.             fg = "#9999"+str(i*2)[0]+str(i*3)[0]
  222.             Label(self.u2_frame,text = float(self.tarif[i]), bg = fg,
  223.             font = "Arial 20").place(x=401, y=80+50*i+3*i, anchor="c", height=40, width=260)
  224.  
  225.         for i in range(5):
  226.             fg = "#9999"+str(i*2)[0]+str(i*3)[0]
  227.             Label(self.u2_frame,text = self.spisok[i](self),bg = fg,
  228.             font = "Arial 20").place(x=668, y=80+50*i+3*i, anchor="c", height=40, width=260)
  229.  
  230.         Label(self.u2_frame,text = "Итого",bg = "#F3DA0B",
  231.             font = "Arial 20").place(x=134, y=80+50*6+3*6, anchor="c", height=40, width=260)
  232.  
  233.         Label(self.u2_frame,text = self.summ(), bg = "#F3DA0B",
  234.             font = "Arial 20").place(x=135+270-4, y=80+50*6+3*6, anchor="c", height=40, width=250)
  235.  
  236. g = Grafic()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement