Advertisement
ALEXANDAR_GEORGIEV

list_derections

Jun 18th, 2023
700
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.51 KB | Source Code | 0 0
  1. from json import dump
  2. import tkinter as tk
  3.  
  4.  
  5. class TravelDirections:
  6.     def __init__(self, dir_update=None):
  7.  
  8.         self.directions = tk.Tk()
  9.         self.directions.title("Направления на автомобилите")
  10.         screen_width = self.directions.winfo_screenwidth()
  11.         screen_height = self.directions.winfo_screenheight()
  12.         w, h = 800, 800
  13.         print(f"{screen_width} x {screen_height}")
  14.         self.directions.geometry(f"{w}x{h}+{int(screen_width / 2 - w / 2)}+{int(screen_height / 2 - h / 2)}")
  15.         self.screen_width = self.directions.winfo_screenwidth()
  16.         self.directions.attributes('-topmost', True)
  17.  
  18.         # TODO -> Frames
  19.         self.frame_data = tk.Frame(self.directions, width=700, height=400, relief="groove", borderwidth=5,)
  20.         self.frame_data.grid(row=0, column=0, sticky="ewns", pady=(0, 6))
  21.         self.frame_bottom = tk.Frame(self.directions, width=100, height=100, borderwidth=5)
  22.         self.frame_bottom.grid(row=1, column=0, columnspan=2, sticky="ewns")
  23.         self.frame_right = tk.Frame(self.directions, width=100, height=100, borderwidth=5)
  24.         self.frame_right.grid(row=0, column=1, rowspan=2, sticky="ewns")
  25.  
  26.         self.new_dir_e = tk.Entry()
  27.         self.on_update = dir_update
  28.         self.common_dir = ("Основна д/ст", "Спомагателна д/ст", "Търговска д/ст", "Административна д/ст")
  29.         self.custom_dir = []
  30.  
  31.         self.list_dir = {}
  32.  
  33.     def ok_b(self):
  34.         pass
  35.  
  36.     def delete_b(self):
  37.         pass
  38.  
  39.     def save_b(self):
  40.         pass
  41.         new_dir = self.new_dir_e.get()
  42.         if new_dir != "" and new_dir != " " and new_dir is not None:
  43.             if new_dir not in self.custom_dir:
  44.                 self.custom_dir.append(new_dir)
  45.                 print(self.custom_dir)
  46.  
  47.         if self.custom_dir:
  48.             self.custom_dir.sort()
  49.             r, c = 0, 0
  50.             for lab in self.custom_dir:
  51.                 self.create_label(self.frame_right, lab, "purple", r, c )
  52.                 r += 1
  53.  
  54.         # # TODO -> ДОбавя се в базата JSON file новата кола
  55.         # with open("db/list_directions.json", "a", encoding=('UTF-8')) as json_file:   # , encoding="utf-8"
  56.         #     dump(self.car_init, json_file, ensure_ascii=False)
  57.         #     json_file.write("\n")
  58.         #
  59.         # print(f"CarProperties::save_b() self.on_update {self.on_update}")
  60.         # if (self.on_update):
  61.         #     self.on_update()
  62.  
  63.         # self.directions.destroy()
  64.  
  65.     def dir(self):
  66.         # TODO -> Labels
  67.         tk.Label(self.frame_data, text="Въведи ново направление - >", ).grid(row=0, column=0, padx=20, pady=(10), sticky="w")
  68.         tk.Label(self.frame_data, text="Направления по подразбиране - >").grid(row=1, column=0, padx=20, pady=(1, 1), sticky="w")
  69.  
  70.         # TODO -> Entry
  71.         self.new_dir_e = tk.Entry(self.frame_data, width=40, justify='center', name="new_dir_e")
  72.         self.new_dir_e.grid(row=0, column=1, padx=10, pady=10, sticky="w")
  73.  
  74.         # TODO -> Buttons
  75.         save_b = tk.Button(self.frame_data, text="ЗАПИС", fg="blue", width=10, font=("Bookman Old Style Bold", 8), command=self.save_b)
  76.         save_b.grid(row=0, column=2, padx=(20, 10))
  77.  
  78.         ok_b = tk.Button(self.frame_bottom, text="ОК", fg="green", width=10, font=("Bookman Old Style Bold", 8), command=self.ok_b)
  79.         ok_b.grid(row=0, column=2, padx=(20, 10))
  80.  
  81.         delete_b = tk.Button(self.frame_bottom, text="ИЗТРИВАНЕ", fg="purple", width=10, font=("Bookman Old Style Bold", 8), command=self.delete_b)
  82.         delete_b.grid(row=0, column=3, padx=(20, 10))
  83.  
  84.         # TODO -> common Labels directions
  85.         r = 1
  86.         for lab in self.common_dir:
  87.             self.create_label(self.frame_data, lab, "blue", r, )
  88.             r += 1
  89.  
  90.     def create_label(self, frame, text, f_col, row, col=1):
  91.         tk.Label(frame, text=text, fg=f_col, justify='left').grid(row=row, column=col, sticky='w', padx=(10, 0), pady=(1,1))
  92.  
  93.  
  94.  
  95.     def have_new_data(self):  # Проверка дали има нова кола
  96.  
  97.         # unmapped_acc = self.acc_tree.get_unmapped_acc(self.mapped_accounts)
  98.         # print("unmapped_acc", unmapped_acc)
  99.         if len(self.list_dir) == 0:
  100.             return False
  101.         return True
  102.         # self.properties.mainloop()
  103.  
  104.  
  105. if __name__ == '__main__':
  106.     test = TravelDirections()
  107.     test.dir()
  108.  
  109.     test.directions.mainloop()
  110.  
  111.  
  112.  
  113.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement