Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- class CommunalPayments:
- def __init__(self, tarif):
- self.square = 75
- self.tarif = tarif
- self.counter = {"hotwater":[0,0], "coldwater":[0,0], "gas": [0,0], "heating": [0,0], "electricity":[0,0]}
- def setSquare(self, square):
- self.square = square
- def setCounter(self, key, left='', right=''):
- if left != '' and right != '':
- self.counter[key] = left, right
- elif right == '':
- self.counter[key][0] = left
- elif left != '':
- self.counter[key][1] = right
- def hot_water(self):
- return round((self.counter["hotwater"][1] - self.counter["hotwater"][0]) * self.tarif[0], 3)
- def cold_water(self):
- return round((self.counter["coldwater"][1] - self.counter["coldwater"][0]) * self.tarif[1], 3)
- def gas(self):
- return round((self.counter["gas"][1] - self.counter["gas"][0]) * self.tarif[2], 3)
- def heating(self):
- by_area_apartment = self.counter["heating"][1] * self.square / 7000 * self.tarif[3]
- heat_volume = self.counter["heating"][1] * (1 - 6000 / 7000) * self.square / 6000
- return round(by_area_apartment + heat_volume * self.tarif[3], 3)
- #https://otoplenie-doma.org/kak-rasschityvaetsya-otoplenie-v-kvartire.html
- def electricity(self):
- return round((self.counter["electricity"][1] - self.counter["electricity"][0]) * self.tarif[4], 3)
- def summ(self):
- return self.hot_water()+ self.cold_water() + self.gas() + self.heating() + self.electricity()
- spisok = [hot_water, cold_water, gas, heating, electricity]
- class Grafic(CommunalPayments):
- def __init__(self):
- CommunalPayments.__init__(self, [205.15 , 39.28, 5.56151, 1400, 4.98])
- self.button_number = 0
- self.list_name =[ ["hotwater", "coldwater", "gas", "heating", "electricity"],
- ["Горячая вода", "Холодная вода", "Газ", "Отопление", "Электроэнергия"] ]
- self.root = Tk()
- self.root.title("Коммунальные платежи")
- self.u1_frame = Frame(self.root, width=800, height=80, bg ='#068888')
- self.u1_frame.grid(row=0, column=0, padx=10, pady=5)
- self.u2_frame = Frame(self.root, width=800, height=480, bg ='#068888')
- self.u2_frame.grid(row=1, column=0, padx=10, pady=5)
- b_counter = Button(self.u1_frame, text='Ввести показания', command=self.b_left,
- bg='#ffffff', foreground='#000000', font = "Arial 20")
- b_counter.place(x=150, y=40, anchor="c", height=40, width=270, bordermode=OUTSIDE)
- b_withdrawing_funds = Button(self.u1_frame, text='Посмотреть тариф и свои расходы', command=self.b_right,
- bg='#ffffff', foreground='#000000', font = "Arial 20")
- b_withdrawing_funds.place(x=540, y=40, anchor="c", height=40, width=480, bordermode=OUTSIDE)
- self.b_left()
- self.root.mainloop()
- #___________________________________________________________________________
- def is_digit(self, entry):
- if entry.isdigit():
- return True
- else:
- try:
- float(entry)
- return True
- except ValueError:
- return False
- def renovation_U2(self):
- self.button_number = 0
- try:
- self.u2_frame.destroy()
- except:
- pass
- self.u2_frame = Frame(self.root, width=800, height=480, bg ='#068888')
- self.u2_frame.grid(row=1, column=0, padx=10, pady=5)
- def send(self): #b_left/which_button
- key = self.list_name[0][self.button_number]
- e_list = [self.is_digit(self.e1_send.get()), self.is_digit(self.e2_send.get()) , False]
- try:
- e_list[2] = self.is_digit(self.e3_send.get())
- except:
- pass
- if e_list[0] == True and e_list[1] == True and e_list[2] == True:
- entry_counter = "Изменены предыдущие и текущие показания и площадь"
- font = "Arial 13"
- elif e_list[0] == True and e_list[1] == True and e_list[2] == False:
- entry_counter = "Изменены предыдущие и текущие показания"
- font = "Arial 16"
- elif e_list[0] == True and e_list[1] == False and e_list[2] == False:
- entry_counter = "Изменены предыдущие показания"
- font = "Arial 20"
- elif e_list[0] == False and e_list[1] == True and e_list[2] == False:
- entry_counter = "Изменены текущие показания"
- font = "Arial 20"
- elif e_list[0] == True and e_list[1] == False and e_list[2] == True:
- entry_counter = "Изменены предыдущие показания и площадь"
- font = "Arial 16"
- elif e_list[0] == False and e_list[1] == True and e_list[2] == True:
- entry_counter = "Изменены текущие показания и площадь"
- font = "Arial 16"
- elif e_list[0] == False and e_list[1] == False and e_list[2] == True:
- entry_counter = "Изменена площадь"
- font = "Arial 16"
- elif e_list[0] == False and e_list[1] == False and e_list[2] == False:
- entry_counter = "!ОШИБКА! Вы не ввели показания"
- font = "Arial 19"
- if not e_list[0]:
- e1_float = self.counter[key][0]
- else:
- e1_float = float(self.e1_send.get())
- if not e_list[1]:
- e2_float = self.counter[key][1]
- else:
- e2_float = float(self.e2_send.get())
- if e_list[2]:
- e3_float = float(self.e3_send.get())
- self.square = e3_float
- if e1_float <= e2_float:
- self.setCounter(key, e1_float, e2_float)
- else:
- entry_counter = "!ОШИБКА! Предыдущие > Текущие "
- self.l_notification["text"] = entry_counter
- self.l_notification["font"] = font
- def which_button(self, i): #b_left
- self.root.title("Коммунальные платежи - Ввести показания - " + self.list_name[1][i])
- fg = "#9999"+str(i*2)[0]+str(i*3)[0]
- if self.button_number != i:
- try:
- self.l3_send.destroy()
- self.e3_send.destroy()
- except:
- pass
- self.b_send.destroy()
- self.b_send = Button(self.u2_frame, text='Отправить данные', command=self.send,
- bg='#ffffff', foreground='#000000', font = "Arial 20")
- self.b_send.place(x=590, y=40*5+8, anchor="c", height=40, width=260, bordermode=OUTSIDE)
- self.l_notification["text"] = "Выбрано - " + self.list_name[1][i]
- self.l_notification["font"] = "Arial 20"
- self.l_notification["bg"] = "#9999"+str(i*2)[0]+str(i*3)[0]
- if i == 3:
- self.l3_send = Label(self.u2_frame,text = "Введите площадь:", font = "Arial 20")
- self.l3_send.place(x=460, y=40*5+8, anchor="c", height=40, width=360)
- self.e3_send = Entry(self.u2_frame, bg='#ffffff', foreground='#000000', justify='center', font = "Arial 18")
- self.e3_send.place(x=720, y=40*5+8, anchor="c", height=40, width=130, bordermode=OUTSIDE)
- self.b_send.destroy()
- self.b_send = Button(self.u2_frame, text='Отправить данные', command=self.send,
- bg='#ffffff', foreground='#000000', font = "Arial 20")
- self.b_send.place(x=590, y=40*7+12, anchor="c", height=40, width=260, bordermode=OUTSIDE)
- self.button_number = i
- def b_left(self): #НАЧАЛО
- self.renovation_U2()
- self.root.title("Коммунальные платежи - Ввести показания - " + self.list_name[1][0])
- for i in range(5):
- fg = "#9999"+str(i*2)[0]+str(i*3)[0]
- Button(self.u2_frame, text=self.list_name[1][i], command=lambda id=i: self.which_button(id),
- bg=fg, foreground='#000000',
- font = "Arial 20").place(x=140, y=40*(i+1)+2*i, anchor="c",
- height=40, width=250, bordermode=OUTSIDE)
- l1_send = Label(self.u2_frame,text = "Предыдущие показания:", font = "Arial 20")
- l1_send.place(x=460, y=40, anchor="c", height=40, width=360)
- self.e1_send = Entry(self.u2_frame, bg='#ffffff', foreground='#000000', justify='center', font = "Arial 18")
- self.e1_send.place(x=720, y=40, anchor="c", height=40, width=130, bordermode=OUTSIDE)
- l2_send = Label(self.u2_frame,text = "Новые показания:", font = "Arial 20")
- l2_send.place(x=460, y=40*3+2, anchor="c", height=40, width=360)
- self.e2_send = Entry(self.u2_frame, bg='#ffffff', foreground='#000000', justify='center', font = "Arial 18")
- self.e2_send.place(x=720, y=40*3+2, anchor="c", height=40, width=130, bordermode=OUTSIDE)
- self.b_send = Button(self.u2_frame, text='Отправить данные', command=self.send,
- bg='#ffffff', foreground='#000000', font = "Arial 20")
- self.b_send.place(x=590, y=40*5+8, anchor="c", height=40, width=260, bordermode=OUTSIDE)
- self.l_notification = Label(self.u2_frame,text = "По умолчанию - Горячая вода",bg = "#00FF00", font = "Arial 20")
- self.l_notification.place(x=400, y=40*9+14, anchor="c", height=50, width=460)
- def b_right(self): #НАЧАЛО
- self.renovation_U2()
- self.root.title("Коммунальные платежи - Посмотреть тариф и свои расходы")
- Label(self.u2_frame,text = "Услуга",bg = "#00FF00",
- font = "Arial 20").place(x=134, y=25, anchor="c", height=40, width=260)
- Label(self.u2_frame,text = "Тариф",bg = "#00FF00",
- font = "Arial 20").place(x=135+270-4, y=25, anchor="c", height=40, width=260)
- Label(self.u2_frame,text = "Расходы",bg = "#00FF00",
- font = "Arial 20").place(x=130+270*2-2, y=25, anchor="c", height=40, width=260)
- for i in range(5):
- fg = "#9999"+str(i*2)[0]+str(i*3)[0]
- Label(self.u2_frame,text = self.list_name[1][i],bg = fg,
- font = "Arial 20").place(x=134, y=80+50*i+3*i, anchor="c", height=40, width=260)
- for i in range(5):
- fg = "#9999"+str(i*2)[0]+str(i*3)[0]
- Label(self.u2_frame,text = float(self.tarif[i]), bg = fg,
- font = "Arial 20").place(x=401, y=80+50*i+3*i, anchor="c", height=40, width=260)
- for i in range(5):
- fg = "#9999"+str(i*2)[0]+str(i*3)[0]
- Label(self.u2_frame,text = self.spisok[i](self),bg = fg,
- font = "Arial 20").place(x=668, y=80+50*i+3*i, anchor="c", height=40, width=260)
- Label(self.u2_frame,text = "Итого",bg = "#F3DA0B",
- font = "Arial 20").place(x=134, y=80+50*6+3*6, anchor="c", height=40, width=260)
- Label(self.u2_frame,text = self.summ(), bg = "#F3DA0B",
- font = "Arial 20").place(x=135+270-4, y=80+50*6+3*6, anchor="c", height=40, width=250)
- g = Grafic()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement