Advertisement
ALEXANDAR_GEORGIEV

row_generator_insert_del

Jul 26th, 2023
795
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.84 KB | Source Code | 0 0
  1. from tkinter import Frame, Label, Tk, CENTER, LEFT, RIGHT, Entry, Button
  2. from tkinter import ttk
  3.  
  4. class TravelReport:
  5.     def __init__(self):
  6.         self.window = Tk()
  7.         self.window.title('Пътен лист 2023г.')
  8.         self.window.geometry('1200x840+200+10')
  9.         self.window.resizable(True, False)
  10.         self.window.attributes('-topmost', 'true')
  11.  
  12.         self.widgets = {}
  13.  
  14.         self.first_data_line_row = 0
  15.         self.data_lines_count = 0
  16.  
  17.         self.frame_1 = self.get_frame(place_on=self.window)
  18.         self.create_travel_rep()
  19.         add_row = Button(self.window, text="Нов ред", width=8, command=self.add_row)
  20.         add_row.grid(row=0, column=1)
  21.  
  22.         del_row = Button(self.window, text="Изтрий", width=8, command=self.del_last_row)
  23.         del_row.grid(row=1, column=1)
  24.  
  25.  
  26.         self.window.mainloop()
  27.  
  28.     def get_label(self, place_on, row_x, col_y, span_row=1, span_col=1, height=1, text='', anc=CENTER):
  29.         label = Label(place_on, text=text, font=('Times New Roman', 10, 'bold'), bg='white', height=height,
  30.                     anchor=anc, fg='black', justify='center', )
  31.         label.grid(row=row_x, column=col_y, padx=(1, 1), pady=(1, 1), sticky='nswe', rowspan=span_row, columnspan=span_col)
  32.         return label
  33.  
  34.     # -----------------FRAMES------------------------------------------------
  35.     def get_frame(self, place_on, ):
  36.         frame = Frame(place_on,  width=100, height=100)
  37.         frame.grid(row=0, column=0)
  38.         return frame
  39.  
  40.     # -----------------ENTRIES------------------------------------------------
  41.     def get_entry(self, place_on, r, c,  j=LEFT, name=None, space_x=(1, 1) ):
  42.  
  43.         entry = Entry(place_on, bd=2, name=name, justify=j, relief="flat")
  44.         # entry.place(x=x, y=y)
  45.         entry.grid(row=r, column=c, padx=space_x, pady=1)
  46.         return entry
  47.  
  48.     def create_row(self, place_on, r):   # Свеки ред е съставен от Label + Entry x 15
  49.         self.get_entry(place_on=place_on, r=r, c=0,)
  50.         self.get_entry(place_on=place_on, r=r, c=1,)
  51.         self.get_entry(place_on=place_on, r=r, c=2,)
  52.         self.get_entry(place_on=place_on, r=r, c=3,)
  53.         self.get_label(place_on=place_on, row_x=r, col_y=4,)
  54.         self.get_entry(place_on=place_on, r=r, c=5,)
  55.         self.get_entry(place_on=place_on, r=r, c=6,)
  56.         self.get_entry(place_on=place_on, r=r, c=7,)
  57.         pass
  58.  
  59.     def get_widget_name(self):
  60.         pass
  61.  
  62.     def create_travel_rep(self):
  63.         frame_1 = self.frame_1
  64.  
  65.         self.get_label(place_on=frame_1, row_x=0, col_y=0, text="РВ 9449 АР", height=1)
  66.         self.get_label(place_on=frame_1, row_x=1, col_y=0, text="БЕНЗИН", height=1)
  67.         # get_list_box или combo_box за избор на месеца
  68.         self.get_label(place_on=frame_1, row_x=1, col_y=3, height=1, text="Януари",)
  69.         self.get_label(place_on=frame_1, row_x=0, col_y=6, height=1, text="обем: ")
  70.         self.get_label(place_on=frame_1, row_x=0, col_y=7, height=1, text="60 л")
  71.         self.get_label(place_on=frame_1, row_x=1, col_y=6, height=1, text="л/100км:")
  72.         self.get_label(place_on=frame_1, row_x=1, col_y=7, height=1, text="5,20")
  73.         self.get_label(place_on=frame_1, row_x=2, col_y=6, height=1, text="Наличност:")
  74.         self.get_label(place_on=frame_1, row_x=2, col_y=7, height=1, text="52,25")
  75.         self.get_label(place_on=frame_1, row_x=3, col_y=0, height=2, text="от\nдата")
  76.         self.get_label(place_on=frame_1, row_x=3, col_y=1, height=2, text="до\nдата")
  77.         self.get_label(place_on=frame_1, row_x=3, col_y=2, height=2, text="Начален\nкилометраж")
  78.         self.get_label(place_on=frame_1, row_x=3, col_y=3, height=2, text="Краен\nкилометраж")
  79.         self.get_label(place_on=frame_1, row_x=3, col_y=4, height=2, text="Пробег")
  80.         self.get_label(place_on=frame_1, row_x=3, col_y=5, height=2, text="Направление")
  81.         self.get_label(place_on=frame_1, row_x=3, col_y=6, height=2, text="Заредено\n(литри)")
  82.         self.get_label(place_on=frame_1, row_x=3, col_y=7, height=2, text="лева")
  83.  
  84.         self.first_data_line_row = 4
  85.  
  86.         self.create_row(frame_1, 4)
  87.         self.data_lines_count += 1
  88.  
  89.         self.create_row(frame_1, 5)
  90.         self.data_lines_count += 1
  91.  
  92.         self.get_label(place_on=frame_1, row_x=32, col_y=3, text="ОБЩО:")
  93.         self.get_label(place_on=frame_1, row_x=32, col_y=4, text="10 250")
  94.         self.get_label(place_on=frame_1, row_x=32, col_y=6, text="538,25")
  95.         self.get_label(place_on=frame_1, row_x=32, col_y=7, text="1 355,89")
  96.  
  97.         self.get_label(place_on=frame_1, row_x=33, col_y=4, text="10 000")
  98.         self.get_label(place_on=frame_1, row_x=33, col_y=3, text="по направление")
  99.         self.get_label(place_on=frame_1, row_x=33, col_y=6, text="Разход (л):")
  100.         self.get_label(place_on=frame_1, row_x=33, col_y=7, text="135,66")
  101.  
  102.         self.get_label(place_on=frame_1, row_x=34, col_y=4, text="250")
  103.         self.get_label(place_on=frame_1, row_x=34, col_y=3, text="лични нужди")
  104.         self.get_label(place_on=frame_1, row_x=34, col_y=6, text="Разход (лв)")
  105.         self.get_label(place_on=frame_1, row_x=34, col_y=7, text="450,51")
  106.  
  107.         self.get_label(place_on=frame_1, row_x=35, col_y=6, text="Остатък (л):")
  108.         self.get_label(place_on=frame_1, row_x=35, col_y=7, text="53,33")
  109.  
  110.     def add_row(self):
  111.         if self.data_lines_count > 20:
  112.             return
  113.         self.data_lines_count += 1
  114.         new_data_line_row = self.first_data_line_row + self.data_lines_count
  115.         self.create_row(self.frame_1, new_data_line_row)
  116.  
  117.     def del_last_row(self):
  118.         if self.data_lines_count < 3:
  119.             return
  120.         last_data_line_row = self.first_data_line_row + self.data_lines_count
  121.         for col in range(7+1):
  122.             widgets = self.frame_1.grid_slaves(last_data_line_row, col)
  123.             for widget in widgets:
  124.                 widget.grid_remove()
  125.                 del(widget)
  126.  
  127.         self.data_lines_count -= 1
  128.  
  129.  
  130. if __name__ == '__main__':
  131.     # window = Tk()
  132.     # window.title('Пътен лист 2023г.')
  133.     # window.geometry('1200x840+200+10')
  134.     # window.resizable(True, False)
  135.     # window.attributes('-topmost', 'true')
  136.     tr = TravelReport()
  137.  
  138.     # frame_1 = tr.get_frame(place_on=window)
  139.     # tr.create_travel_rep()
  140.     # add_row = Button(window, text="Нов ред", width=8, command=self.add)
  141.     # add_row.grid(row=0, column=1)
  142.     # # col = 0
  143.     # # for i in range(8):
  144.     # #     w = 8
  145.     # #     space = (1, 1)
  146.     # #     if i == 6:
  147.     # #         space = (10, 1)
  148.     # #     new_entry = tr.get_entry(geo=frame_1,r=0, c=col, w=w, space_x=space)
  149.     # #     col += 1
  150.     #
  151.     # window.mainloop()
  152.  
  153.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement