Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- from json import load, loads
- import new_car
- from new_car import *
- def main():
- root = tk.Tk()
- w = 500
- h = 260
- root.geometry(f"{w}x{h}+0+0")
- root.title("УПРАВЛЕНИЕ НА МОТОРНИ ПРЕВОЗНИ СРЕДСТВА")
- # screen_width = root.winfo_screenwidth()
- Main(root)
- root.mainloop()
- class Main:
- def __init__(self, root):
- # TODO -> Frames
- self.frame_up = tk.Frame(root, bg="lightblue", relief="groove", borderwidth=3, height=1)
- self.frame_up.pack(side="top", fill="both", pady=(2, 3) )
- self.frame_down = tk.Frame(root, )
- # self.frame_down.grid(row=1, column=1, sticky="ew", pady=(10, 20), padx=(2, 10))
- self.frame_down.pack(side="bottom", fill="both", expand=True, pady=(2, 2))
- # TODO -> Buttons
- self.new_car_b = tk.Button(self.frame_up, text="НОВ\nавтомобил", fg="#7905ed", activebackground="orange",
- font=("Bookman Old Style Bold", 8), relief='raised', width=10, command=self.get_new_car)
- self.new_car_b.grid(row=0, column=0, padx=1, pady=1, sticky="w")
- self.direction_exp_b = tk.Button(self.frame_up, text="Добави\nнаправление", fg="#7905ed", activebackground="orange",
- font=("Bookman Old Style Bold", 8), relief='raised', width=10, command=self.add_directions)
- self.direction_exp_b.grid(row=0, column=1, padx=1, pady=1, sticky="w")
- self.car_list = []
- self.list_icons = {}
- self.car_numbers = tk.BooleanVar(root, value=False)
- print(self.car_numbers.get())
- # TODO -> car_Buttons
- #self.create_icon()
- self.update_view()
- def clear_icons_frame(self):
- for widget in self.frame_down.winfo_children():
- widget.destroy()
- def create_icon(self, inx, reg_num, tank, type_fuel, type_car):
- icon_b = tk.Button(self.frame_down, text=reg_num, relief="raised", font=("Bookman Old Style Bold", 8), activebackground="orange")
- icon_b.grid(row=0, column=inx, padx=(10, 0))
- tk.Label(self.frame_down, text="наличност: 40 л", font=("Times", 7), name="fuel_rest").grid(row=1, column=inx, padx=(10, 0),),
- tk.Label(self.frame_down, text=f"обем: {tank}", font=("Times", 7)).grid(row=2, column=inx, padx=(10, 0)),
- tk.Label(self.frame_down, text=f"{type_fuel}", font=("Times", 7)).grid(row=3, column=inx, padx=(10, 0)),
- tk.Label(self.frame_down, text=f"{type_car}", font=("Times", 7)).grid(row=4, column=inx, padx=(10, 0)),
- tk.Label(self.frame_down, text="21.12.2023г", font=("Times", 7)).grid(row=5, column=inx, padx=(10, 0)),
- def update_view(self):
- self.new_car_b['state'] = "normal"
- self.clear_icons_frame()
- # TODO -> Четем JSON файла ред по ред
- indx = 0
- try:
- with open("db/list_cars.json", "r", encoding="UTF-8") as json_list_cars:
- for car in json_list_cars:
- self.car_list.append(loads(car))
- #print(f"TOWA: {self.car_list[indx]['reg_number_e']}")
- self.create_icon(indx, self.car_list[indx]['reg_number_e'], self.car_list[indx]['tank_e'], self.car_list[indx]['fuel_type_e'], self.car_list[indx]['type_car_e'])
- indx += 1
- #break
- except:
- return None
- print(self.car_list)
- # TODO -> Правим ИКОНИТЕ
- count_cars = len(self.car_list)
- for line in range(1, count_cars + 1):
- pass
- # TODO -> Правим Бутоните и лейбълите като в имената добавяме индекс LINE и увеличаваме в GRID колони и редове с 1
- # TODO -> Или правим само 1 икона и копираме толкова пъти колкото е LEN(self.car_list - 1) тази икона като после добавяме индекси към имената и +1 за GRID
- def create_car_on_main(self):
- pass
- def add_directions(self):
- pass
- def get_new_car(self):
- new_car = CarProperties(self.update_view)
- check = new_car.props()
- self.new_car_b["state"] = "disabled" #
- if check:
- print(" В CHEK -> True")
- self.new_car_b["state"] = "normal"
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement