Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import Frame, Label, Tk, CENTER, LEFT, RIGHT, Entry, Button
- from tkinter import ttk
- class TravelReport:
- def __init__(self):
- self.window = Tk()
- self.window.title('Пътен лист 2023г.')
- self.window.geometry('1200x840+200+10')
- self.window.resizable(True, False)
- self.window.attributes('-topmost', 'true')
- self.widgets = {}
- self.first_data_line_row = 0
- self.data_lines_count = 0
- self.frame_1 = self.get_frame(place_on=self.window)
- self.create_travel_rep()
- add_row = Button(self.window, text="Нов ред", width=8, command=self.add_row)
- add_row.grid(row=0, column=1)
- del_row = Button(self.window, text="Изтрий", width=8, command=self.del_last_row)
- del_row.grid(row=1, column=1)
- self.window.mainloop()
- def get_label(self, place_on, row_x, col_y, span_row=1, span_col=1, height=1, text='', anc=CENTER):
- label = Label(place_on, text=text, font=('Times New Roman', 10, 'bold'), bg='white', height=height,
- anchor=anc, fg='black', justify='center', )
- label.grid(row=row_x, column=col_y, padx=(1, 1), pady=(1, 1), sticky='nswe', rowspan=span_row, columnspan=span_col)
- return label
- # -----------------FRAMES------------------------------------------------
- def get_frame(self, place_on, ):
- frame = Frame(place_on, width=100, height=100)
- frame.grid(row=0, column=0)
- return frame
- # -----------------ENTRIES------------------------------------------------
- def get_entry(self, place_on, r, c, j=LEFT, name=None, space_x=(1, 1) ):
- entry = Entry(place_on, bd=2, name=name, justify=j, relief="flat")
- # entry.place(x=x, y=y)
- entry.grid(row=r, column=c, padx=space_x, pady=1)
- return entry
- def create_row(self, place_on, r): # Свеки ред е съставен от Label + Entry x 15
- self.get_entry(place_on=place_on, r=r, c=0,)
- self.get_entry(place_on=place_on, r=r, c=1,)
- self.get_entry(place_on=place_on, r=r, c=2,)
- self.get_entry(place_on=place_on, r=r, c=3,)
- self.get_label(place_on=place_on, row_x=r, col_y=4,)
- self.get_entry(place_on=place_on, r=r, c=5,)
- self.get_entry(place_on=place_on, r=r, c=6,)
- self.get_entry(place_on=place_on, r=r, c=7,)
- pass
- def get_widget_name(self):
- pass
- def create_travel_rep(self):
- frame_1 = self.frame_1
- self.get_label(place_on=frame_1, row_x=0, col_y=0, text="РВ 9449 АР", height=1)
- self.get_label(place_on=frame_1, row_x=1, col_y=0, text="БЕНЗИН", height=1)
- # get_list_box или combo_box за избор на месеца
- self.get_label(place_on=frame_1, row_x=1, col_y=3, height=1, text="Януари",)
- self.get_label(place_on=frame_1, row_x=0, col_y=6, height=1, text="обем: ")
- self.get_label(place_on=frame_1, row_x=0, col_y=7, height=1, text="60 л")
- self.get_label(place_on=frame_1, row_x=1, col_y=6, height=1, text="л/100км:")
- self.get_label(place_on=frame_1, row_x=1, col_y=7, height=1, text="5,20")
- self.get_label(place_on=frame_1, row_x=2, col_y=6, height=1, text="Наличност:")
- self.get_label(place_on=frame_1, row_x=2, col_y=7, height=1, text="52,25")
- self.get_label(place_on=frame_1, row_x=3, col_y=0, height=2, text="от\nдата")
- self.get_label(place_on=frame_1, row_x=3, col_y=1, height=2, text="до\nдата")
- self.get_label(place_on=frame_1, row_x=3, col_y=2, height=2, text="Начален\nкилометраж")
- self.get_label(place_on=frame_1, row_x=3, col_y=3, height=2, text="Краен\nкилометраж")
- self.get_label(place_on=frame_1, row_x=3, col_y=4, height=2, text="Пробег")
- self.get_label(place_on=frame_1, row_x=3, col_y=5, height=2, text="Направление")
- self.get_label(place_on=frame_1, row_x=3, col_y=6, height=2, text="Заредено\n(литри)")
- self.get_label(place_on=frame_1, row_x=3, col_y=7, height=2, text="лева")
- self.first_data_line_row = 4
- self.create_row(frame_1, 4)
- self.data_lines_count += 1
- self.create_row(frame_1, 5)
- self.data_lines_count += 1
- self.get_label(place_on=frame_1, row_x=32, col_y=3, text="ОБЩО:")
- self.get_label(place_on=frame_1, row_x=32, col_y=4, text="10 250")
- self.get_label(place_on=frame_1, row_x=32, col_y=6, text="538,25")
- self.get_label(place_on=frame_1, row_x=32, col_y=7, text="1 355,89")
- self.get_label(place_on=frame_1, row_x=33, col_y=4, text="10 000")
- self.get_label(place_on=frame_1, row_x=33, col_y=3, text="по направление")
- self.get_label(place_on=frame_1, row_x=33, col_y=6, text="Разход (л):")
- self.get_label(place_on=frame_1, row_x=33, col_y=7, text="135,66")
- self.get_label(place_on=frame_1, row_x=34, col_y=4, text="250")
- self.get_label(place_on=frame_1, row_x=34, col_y=3, text="лични нужди")
- self.get_label(place_on=frame_1, row_x=34, col_y=6, text="Разход (лв)")
- self.get_label(place_on=frame_1, row_x=34, col_y=7, text="450,51")
- self.get_label(place_on=frame_1, row_x=35, col_y=6, text="Остатък (л):")
- self.get_label(place_on=frame_1, row_x=35, col_y=7, text="53,33")
- def add_row(self):
- if self.data_lines_count > 20:
- return
- self.data_lines_count += 1
- new_data_line_row = self.first_data_line_row + self.data_lines_count
- self.create_row(self.frame_1, new_data_line_row)
- def del_last_row(self):
- if self.data_lines_count < 3:
- return
- last_data_line_row = self.first_data_line_row + self.data_lines_count
- for col in range(7+1):
- widgets = self.frame_1.grid_slaves(last_data_line_row, col)
- for widget in widgets:
- widget.grid_remove()
- del(widget)
- self.data_lines_count -= 1
- if __name__ == '__main__':
- # window = Tk()
- # window.title('Пътен лист 2023г.')
- # window.geometry('1200x840+200+10')
- # window.resizable(True, False)
- # window.attributes('-topmost', 'true')
- tr = TravelReport()
- # frame_1 = tr.get_frame(place_on=window)
- # tr.create_travel_rep()
- # add_row = Button(window, text="Нов ред", width=8, command=self.add)
- # add_row.grid(row=0, column=1)
- # # col = 0
- # # for i in range(8):
- # # w = 8
- # # space = (1, 1)
- # # if i == 6:
- # # space = (10, 1)
- # # new_entry = tr.get_entry(geo=frame_1,r=0, c=col, w=w, space_x=space)
- # # col += 1
- #
- # window.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement