Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from json import dump
- import tkinter as tk
- class TravelDirections:
- def __init__(self, dir_update=None):
- self.directions = tk.Tk()
- self.directions.title("Направления на автомобилите")
- screen_width = self.directions.winfo_screenwidth()
- screen_height = self.directions.winfo_screenheight()
- w, h = 800, 800
- print(f"{screen_width} x {screen_height}")
- self.directions.geometry(f"{w}x{h}+{int(screen_width / 2 - w / 2)}+{int(screen_height / 2 - h / 2)}")
- self.screen_width = self.directions.winfo_screenwidth()
- self.directions.attributes('-topmost', True)
- # TODO -> Frames
- self.frame_data = tk.Frame(self.directions, width=700, height=400, relief="groove", borderwidth=5,)
- self.frame_data.grid(row=0, column=0, sticky="ewns", pady=(0, 6))
- self.frame_bottom = tk.Frame(self.directions, width=100, height=100, borderwidth=5)
- self.frame_bottom.grid(row=1, column=0, columnspan=2, sticky="ewns")
- self.frame_right = tk.Frame(self.directions, width=100, height=100, borderwidth=5)
- self.frame_right.grid(row=0, column=1, rowspan=2, sticky="ewns")
- self.new_dir_e = tk.Entry()
- self.on_update = dir_update
- self.common_dir = ("Основна д/ст", "Спомагателна д/ст", "Търговска д/ст", "Административна д/ст")
- self.custom_dir = []
- self.list_dir = {}
- def ok_b(self):
- pass
- def delete_b(self):
- pass
- def save_b(self):
- pass
- new_dir = self.new_dir_e.get()
- if new_dir != "" and new_dir != " " and new_dir is not None:
- if new_dir not in self.custom_dir:
- self.custom_dir.append(new_dir)
- print(self.custom_dir)
- if self.custom_dir:
- self.custom_dir.sort()
- r, c = 0, 0
- for lab in self.custom_dir:
- self.create_label(self.frame_right, lab, "purple", r, c )
- r += 1
- # # TODO -> ДОбавя се в базата JSON file новата кола
- # with open("db/list_directions.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.directions.destroy()
- def dir(self):
- # TODO -> Labels
- tk.Label(self.frame_data, text="Въведи ново направление - >", ).grid(row=0, column=0, padx=20, pady=(10), sticky="w")
- tk.Label(self.frame_data, text="Направления по подразбиране - >").grid(row=1, column=0, padx=20, pady=(1, 1), sticky="w")
- # TODO -> Entry
- self.new_dir_e = tk.Entry(self.frame_data, width=40, justify='center', name="new_dir_e")
- self.new_dir_e.grid(row=0, column=1, padx=10, pady=10, sticky="w")
- # TODO -> Buttons
- save_b = tk.Button(self.frame_data, text="ЗАПИС", fg="blue", width=10, font=("Bookman Old Style Bold", 8), command=self.save_b)
- save_b.grid(row=0, column=2, padx=(20, 10))
- ok_b = tk.Button(self.frame_bottom, text="ОК", fg="green", width=10, font=("Bookman Old Style Bold", 8), command=self.ok_b)
- ok_b.grid(row=0, column=2, padx=(20, 10))
- delete_b = tk.Button(self.frame_bottom, text="ИЗТРИВАНЕ", fg="purple", width=10, font=("Bookman Old Style Bold", 8), command=self.delete_b)
- delete_b.grid(row=0, column=3, padx=(20, 10))
- # TODO -> common Labels directions
- r = 1
- for lab in self.common_dir:
- self.create_label(self.frame_data, lab, "blue", r, )
- r += 1
- def create_label(self, frame, text, f_col, row, col=1):
- tk.Label(frame, text=text, fg=f_col, justify='left').grid(row=row, column=col, sticky='w', padx=(10, 0), pady=(1,1))
- def have_new_data(self): # Проверка дали има нова кола
- # unmapped_acc = self.acc_tree.get_unmapped_acc(self.mapped_accounts)
- # print("unmapped_acc", unmapped_acc)
- if len(self.list_dir) == 0:
- return False
- return True
- # self.properties.mainloop()
- if __name__ == '__main__':
- test = TravelDirections()
- test.dir()
- test.directions.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement