Advertisement
ALEXANDAR_GEORGIEV

main

Jun 8th, 2023 (edited)
776
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.47 KB | Source Code | 0 0
  1. import tkinter as tk
  2. from json import load, loads
  3.  
  4. import new_car
  5. from new_car import *
  6.  
  7.  
  8. def main():
  9.     root = tk.Tk()
  10.     w = 500
  11.     h = 260
  12.     root.geometry(f"{w}x{h}+0+0")
  13.     root.title("УПРАВЛЕНИЕ НА МОТОРНИ ПРЕВОЗНИ СРЕДСТВА")
  14.     # screen_width = root.winfo_screenwidth()
  15.     Main(root)
  16.  
  17.     root.mainloop()
  18.  
  19.  
  20. class Main:
  21.     def __init__(self, root):
  22.         # TODO -> Frames
  23.         self.frame_up = tk.Frame(root, bg="lightblue", relief="groove", borderwidth=3, height=1)
  24.         self.frame_up.pack(side="top", fill="both", pady=(2, 3) )
  25.  
  26.         self.frame_down = tk.Frame(root, )
  27.         # self.frame_down.grid(row=1, column=1, sticky="ew", pady=(10, 20), padx=(2, 10))
  28.         self.frame_down.pack(side="bottom", fill="both", expand=True, pady=(2, 2))
  29.         # TODO -> Buttons
  30.         self.new_car_b = tk.Button(self.frame_up, text="НОВ\nавтомобил", fg="#7905ed", activebackground="orange",
  31.                         font=("Bookman Old Style Bold", 8), relief='raised', width=10,  command=self.get_new_car)
  32.         self.new_car_b.grid(row=0, column=0, padx=1, pady=1, sticky="w")
  33.  
  34.         self.direction_exp_b = tk.Button(self.frame_up, text="Добави\nнаправление", fg="#7905ed", activebackground="orange",
  35.                         font=("Bookman Old Style Bold", 8), relief='raised', width=10,  command=self.add_directions)
  36.         self.direction_exp_b.grid(row=0, column=1, padx=1, pady=1, sticky="w")
  37.  
  38.         self.car_list = []
  39.         self.list_icons = {}
  40.         self.car_numbers = tk.BooleanVar(root, value=False)
  41.         print(self.car_numbers.get())
  42.         # TODO -> car_Buttons
  43.         #self.create_icon()
  44.         self.update_view()
  45.  
  46.     def clear_icons_frame(self):
  47.         for widget in self.frame_down.winfo_children():
  48.             widget.destroy()
  49.  
  50.     def create_icon(self, inx, reg_num, tank, type_fuel, type_car):
  51.         icon_b = tk.Button(self.frame_down, text=reg_num, relief="raised", font=("Bookman Old Style Bold", 8), activebackground="orange")
  52.         icon_b.grid(row=0, column=inx, padx=(10, 0))
  53.  
  54.         tk.Label(self.frame_down, text="наличност: 40 л", font=("Times", 7), name="fuel_rest").grid(row=1, column=inx, padx=(10, 0),),
  55.         tk.Label(self.frame_down, text=f"обем: {tank}", font=("Times", 7)).grid(row=2, column=inx, padx=(10, 0)),
  56.         tk.Label(self.frame_down, text=f"{type_fuel}", font=("Times", 7)).grid(row=3, column=inx, padx=(10, 0)),
  57.         tk.Label(self.frame_down, text=f"{type_car}", font=("Times", 7)).grid(row=4, column=inx, padx=(10, 0)),
  58.         tk.Label(self.frame_down, text="21.12.2023г", font=("Times", 7)).grid(row=5, column=inx, padx=(10, 0)),
  59.  
  60.  
  61.     def update_view(self):
  62.  
  63.         self.new_car_b['state'] = "normal"
  64.         self.clear_icons_frame()
  65.  
  66.         # TODO -> Четем JSON файла ред по ред
  67.         indx = 0
  68.  
  69.         try:
  70.             with open("db/list_cars.json", "r", encoding="UTF-8") as json_list_cars:
  71.                 for car in json_list_cars:
  72.                     self.car_list.append(loads(car))
  73.                     #print(f"TOWA: {self.car_list[indx]['reg_number_e']}")
  74.                     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'])
  75.                     indx += 1
  76.                     #break
  77.         except:
  78.             return None
  79.         print(self.car_list)
  80.         # TODO -> Правим ИКОНИТЕ
  81.         count_cars = len(self.car_list)
  82.         for line in range(1, count_cars + 1):
  83.             pass
  84.         # TODO -> Правим Бутоните и лейбълите като в имената добавяме индекс LINE и увеличаваме в GRID колони и редове с 1
  85.         # TODO -> Или правим само 1 икона и копираме толкова пъти колкото е LEN(self.car_list - 1) тази икона като после добавяме индекси към имената и +1 за GRID
  86.  
  87.  
  88.     def create_car_on_main(self):
  89.         pass
  90.  
  91.     def add_directions(self):
  92.         pass
  93.  
  94.     def get_new_car(self):
  95.         new_car = CarProperties(self.update_view)
  96.  
  97.         check = new_car.props()
  98.         self.new_car_b["state"] = "disabled"  #
  99.  
  100.         if check:
  101.             print(" В  CHEK -> True")
  102.             self.new_car_b["state"] = "normal"
  103.  
  104.  
  105. if __name__ == '__main__':
  106.  
  107.     main()
  108.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement