Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from json import dump
- import tkinter as tk
- class CarProperties:
- def __init__(self, car_update=None):
- print(f"CarProperties::__init__() car_update {car_update}")
- self.properties = tk.Tk()
- self.properties.title("Информация за автомобила")
- screen_width = self.properties.winfo_screenwidth()
- screen_height = self.properties.winfo_screenheight()
- w, h = 800, 800
- print(f"{screen_width} x {screen_height}")
- self.properties.geometry(f"{w}x{h}+{int(screen_width / 2 - w / 2)}+{int(screen_height / 2 - h / 2)}")
- self.screen_width = self.properties.winfo_screenwidth()
- self.properties.attributes('-topmost', True)
- self.check_status = False
- self.on_update = car_update
- self.entries_list = []
- self.car_init = {}
- self.widgets = {}
- def save_b(self):
- print(f"self.entries_list: {self.entries_list}")
- for entry in self.entries_list:
- self.car_init[f"{entry.winfo_name()}"] = entry.get()
- print(self.car_init)
- # TODO -> ДОбавя се в базата JSON file новата кола
- with open("db/list_cars.json", "a", encoding=('UTF-8')) as json_file: # , encoding="utf-8"
- dump(self.car_init, json_file, ensure_ascii=False)
- json_file.write("\n")
- print(f"CarProperties::save_b() self.on_update {self.on_update}")
- if (self.on_update):
- self.on_update()
- self.properties.destroy()
- def props(self):
- self.check_status = False
- # TODO -> Frames
- frame_data = tk.Frame(self.properties, width=700, height=400, relief="groove", borderwidth=5,)
- frame_data.grid(row=0, column=0, sticky="ewns", pady=(0, 6))
- frame_bottom = tk.Frame(self.properties, width=100, height=100, borderwidth=5)
- frame_bottom.grid(row=1, column=0, columnspan=2, sticky="ewns")
- frame_right = tk.Frame(self.properties, width=100, height=100, borderwidth=5)
- frame_right.grid(row=0, column=1, rowspan=2, sticky="ewns")
- # TODO -> Labels
- tk.Label(frame_data, text="Регистрационен номер:", ).grid(row=0, column=0, padx=20, pady=(10), sticky="w")
- tk.Label(frame_data, text="Модел:").grid(row=1, column=0, padx=20, pady=(10), sticky="w")
- tk.Label(frame_data, text="Обем на резервоара (л):").grid(row=2, column=0, padx=20, pady=(10), sticky="w")
- tk.Label(frame_data, text="Разходна норма min, max, avr (л/100км):").grid(row=3, column=0, padx=20, pady=(10, 10), sticky="w")
- tk.Label(frame_data, text="Гориво:").grid(row=4, column=0, padx=20, pady=(10, 10), sticky="w")
- tk.Label(frame_data, text="Начален километраж:").grid(row=5, column=0, padx=20, pady=(10, 10), sticky="w")
- tk.Label(frame_data, text="Начална дата:").grid(row=6, column=0, padx=20, pady=(10, 10), sticky="w")
- tk.Label(frame_data, text="Технически преглед (дата):").grid(row=7, column=0, padx=20, pady=(10, 10), sticky="w")
- tk.Label(frame_data, text="Данък (дата):").grid(row=8, column=0, padx=20, pady=(10, 10), sticky="w")
- tk.Label(frame_data, text="Венетка (дата):").grid(row=9, column=0, padx=20, pady=(10, 10), sticky="w")
- tk.Label(frame_data, text="Застраховка ГО (дата):").grid(row=10, column=0, padx=20, pady=(10, 10), sticky="w")
- tk.Label(frame_data, text="Застраховка каско (дата):").grid(row=11, column=0, padx=20, pady=(10, 10), sticky="w")
- tk.Label(frame_data, text="Гуми (дата/км):").grid(row=12, column=0, padx=20, pady=(10, 10), sticky="w")
- tk.Label(frame_data, text="Акумулатор (дата):").grid(row=13, column=0, padx=20, pady=(10, 10), sticky="w")
- tk.Label(frame_data, text="Смяна на масло (дата/км):").grid(row=14, column=0, padx=20, pady=(10, 10), sticky="w")
- tk.Label(frame_data, text="Пожарогасител (дата):").grid(row=15, column=0, padx=20, pady=(10, 10), sticky="w")
- tk.Label(frame_data, text="Аптечка (дата):").grid(row=16, column=0, padx=20, pady=(10, 10), sticky="w")
- tk.Label(frame_data, text="Тип автомобил:").grid(row=17, column=0, padx=20, pady=(10, 10), sticky="w")
- # TODO -> Entry
- #self.widgets["reg_number_e"] = tk.Entry(frame_data, width=12, justify='center', name="reg_number_e")
- reg_number_e = tk.Entry(frame_data, width=12, justify='center', name="reg_number_e")
- reg_number_e.grid(row=0, column=1, padx=10, pady=10, sticky="w")
- tk.Entry(frame_data, width=15, justify='left', name="model_e").grid(row=1, column=1, padx=10, pady=10, sticky="w")
- tank_e = tk.Entry(frame_data, width=4, justify='center', name="tank_e")
- tank_e.grid(row=2, column=1, padx=10, pady=10, sticky="w")
- tk.Entry(frame_data, width=4, justify='center', name="fuel_min_e").grid(row=3, column=1, padx=10, pady=10, sticky="w")
- tk.Entry(frame_data, width=4, justify='center', name="fuel_max_e").grid(row=3, column=2, padx=10, pady=10, sticky="w")
- tk.Entry(frame_data, width=4, justify='center', name="fuel_avr_e").grid(row=3, column=3, padx=10, pady=10, sticky="w")
- fuel_type_e = tk.Entry(frame_data, width=12, justify='center', name="fuel_type_e")
- fuel_type_e.grid(row=4, column=1, padx=10, pady=10, sticky="w")
- tk.Entry(frame_data, width=12, justify='center', name="start_km_e").grid(row=5, column=1, padx=10, pady=10, sticky="w")
- start_date_e = tk.Entry(frame_data, width=12, justify='center', name="start_date_e")
- start_date_e.grid(row=6, column=1, padx=10, pady=10, sticky="w")
- tk.Entry(frame_data, width=12, justify='center', name="service_date_e").grid(row=7, column=1, padx=10, pady=10, sticky="w")
- tk.Entry(frame_data, width=12, justify='center', name="tax_date_e").grid(row=8, column=1, padx=10, pady=10, sticky="w")
- tk.Entry(frame_data, width=12, justify='center', name="venete_date_e").grid(row=9, column=1, padx=10, pady=10, sticky="w")
- tk.Entry(frame_data, width=12, justify='center', name="inscomm_date_e").grid(row=10, column=1, padx=10, pady=10, sticky="w")
- tk.Entry(frame_data, width=12, justify='center', name="inscasco_date_e").grid(row=11, column=1, padx=10, pady=10, sticky="w")
- tk.Entry(frame_data, width=12, justify='center', name="tire_date_e").grid(row=12, column=1, padx=10, pady=10, sticky="w")
- tk.Entry(frame_data, width=12, justify='center', name="tire_km_e").grid(row=12, column=2, padx=10, pady=10, sticky="w")
- tk.Entry(frame_data, width=12, justify='center', name="acumul_e").grid(row=13, column=1, padx=10, pady=10, sticky="w")
- tk.Entry(frame_data, width=12, justify='center', name="oil_date_e").grid(row=14, column=1, padx=10, pady=10, sticky="w")
- tk.Entry(frame_data, width=12, justify='center', name="oil_km_e").grid(row=14, column=2, padx=10, pady=10, sticky="w")
- tk.Entry(frame_data, width=12, justify='center', name="fireext_date_e").grid(row=15, column=1, padx=10, pady=10, sticky="w")
- tk.Entry(frame_data, width=12, justify='center', name="aid_date_e").grid(row=16, column=1, padx=10, pady=10, sticky="w")
- type_car_e = tk.Entry(frame_data, width=12, justify='center', name="type_car_e")
- type_car_e.grid(row=17, column=1, padx=10, pady=10, sticky="w")
- self.entries_list = [reg_number_e, tank_e, fuel_type_e, type_car_e, start_date_e]
- # TODO -> Buttons
- save_b = tk.Button(frame_bottom, text="ЗАПИС", fg="blue", command=self.save_b)
- save_b.grid(row=0, column=0, padx=(476, 10))
- # TODO -> Бутона НОВ да се разреши!
- print(f"Opit {self.car_init}")
- # return self.car_init
- return self.check_status
- def have_new_data(self): # Проверка дали има нова кола
- # unmapped_acc = self.acc_tree.get_unmapped_acc(self.mapped_accounts)
- # print("unmapped_acc", unmapped_acc)
- if len(self.car_init) == 0:
- return False
- return True
- # self.properties.mainloop()
- if __name__ == '__main__':
- test = CarProperties()
- test.props()
- # print(test.car_init)
- test.properties.mainloop()
Add Comment
Please, Sign In to add comment