ALEXANDAR_GEORGIEV

travel_reports

Jun 11th, 2023 (edited)
740
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.82 KB | Source Code | 0 0
  1. import tksheet as table
  2. import tkinter as tk
  3.  
  4. from tksheet import theme_light_blue
  5.  
  6.  
  7. def insert_row():
  8.     count_rows = sheet.get_total_rows()
  9.     sheet.insert_row(["Nowiq red"], idx=(count_rows - 4))
  10.  
  11.     print(count_rows)
  12.  
  13.  
  14. def delete_row():
  15.     count_rows = sheet.get_total_rows()
  16.     sheet.delete_row(idx=(count_rows - 5))
  17.  
  18. def save_b():
  19.     quit()
  20.  
  21.  
  22. top = tk.Tk()
  23. top.geometry("760x440") # 640x440
  24. top.title("Пътен лист")
  25.  
  26. # outline_thickness: int = 0,
  27. # outline_color: str = theme_light_blue["outline_color"],
  28. # column_drag_and_drop_perform: bool = True,
  29. # row_drag_and_drop_perform: bool = True,
  30. # empty_horizontal: int = 150,
  31. # empty_vertical: int = 100,
  32. # selected_rows_to_end_of_window: bool = False,
  33. # horizontal_grid_to_end_of_window: bool = False,
  34. # vertical_grid_to_end_of_window: bool = False,
  35. # show_vertical_grid: bool = True,
  36. # show_horizontal_grid: bool = True,
  37.  
  38. sheet = table.Sheet(top, width=640, height=360, outline_thickness = 2, )
  39. sheet.grid()
  40.  
  41. save_b = tk.Button(top, text="ЗАПИС", fg="blue", font=("Bookman Old Style Bold", 8), command=save_b)
  42. save_b.grid(row=1, column=0, pady=20)
  43.  
  44. insert_row_b = tk.Button(top, text="ВМЪКНИ РЕД", command=insert_row)
  45. insert_row_b.grid(row=1, column=1, pady=20, padx=20)
  46.  
  47. delete_row_b = tk.Button(top, text="ИЗТРИЙ РЕД", command=delete_row)
  48. delete_row_b.grid(row=0, column=1, pady=20, padx=20)
  49.  
  50. # sheet.set_sheet_data([[f"{ri+cj}" for cj in range(7)] for ri in range(10)]) # Попълва данните
  51. # sheet.set_sheet_data([[f"" for cj in range(7)] for ri in range(10)]) # Попълва данните
  52. sheet.set_sheet_data([[" ", " ", " ", " ", " ", "РВ 9499 АТ", " ", "обем:", "60 л"],
  53.                       [" ", " ", " ", " ", "Януари", "2023г", " ", "л/100км:", "5.20"],
  54.                       [" ", " ", " ", " ", " ", " ", " ", "Налично (л):", "60.00"],
  55.             ["от дата", "до дата", "Начало км", "Край км", "Пробег", "Направление", " ", "Заредено\n(литри)", "лева"],
  56.             [" "], [" "], [" "], ["ОБЩО:", "", "", "", "10 250"],
  57.             [" ", " ", " ", " ", "10 000", "км направление", " ", "Разход (л):", "29.95"],
  58.                       [" ", " ", " ", " ", "250", "км лични нужди", " ", "Рх (лева):", "59.90"] ,
  59.                      [" ", " ", " ", " ", " ", " ", " ", "Налично (л):", "86.46"], ] ) # Попълва данните
  60.  
  61. # sheet.headers(["Начална\nдата", "Крайна\nдата", "Начален\nкилометраж", "Краен\nкилометраж", "Изминати км", "Направление"])
  62.  
  63. sheet.set_height_of_header_to_text()
  64. sheet.set_column_widths()
  65. sheet.set_all_cell_sizes_to_text()
  66. # sheet.highlight_rows(rows=3, bg="#e4e8f0")
  67. # sheet.highlight_rows(rows=7, bg="#e4e8f0")
  68. # sheet.highlight_cells(row=[0], column=0, cells=[[1, 1], [2, 4]], bg="#c3f760", )
  69. sheet.highlight_cells(cells=[[3, 0], [3, 1], [3, 2], [3, 3], [3, 4], [3, 5], [3, 7], [3, 8]], bg="#e4e8f0", )
  70. sheet.highlight_cells(cells=[[7, 0], [7, 1], [7, 2], [7, 3], [7, 4], [7, 5], [7, 7], [7, 8]], bg="#e4e8f0", )
  71.  
  72.  
  73.  
  74. # table enable choices listed below:
  75. # sheet.set_cell_data(r=1, c=1, value='gggg', redraw=False)
  76. sheet.enable_bindings(("single_select",
  77.                        "row_select",
  78.                        "column_width_resize",
  79.                        "arrowkeys",
  80.                        "right_click_popup_menu",
  81.                        "rc_select",
  82.                        "copy",
  83.                        "cut",
  84.                        "paste",
  85.                        "delete",
  86.                        "undo",  # Ctrl + Z
  87.                        "redo",
  88.                        "edit_cell"
  89.                        ))
  90.  
  91. # sheet.disable_bindings()    # Забранява цялата таблица
  92. # sheet.cell_edit_binding(enable=False, keys=[[4], [5]], )
  93. sheet.readonly_rows(rows=[0], readonly=True, redraw=True)
  94. sheet.readonly_rows(rows=[1], readonly=True, redraw=True)
  95. sheet.readonly_rows(rows=[2], readonly=True, redraw=True)
  96. sheet.readonly_rows(rows=[3], readonly=True, redraw=True)
  97. sheet.readonly_rows(rows=[7], readonly=True, redraw=True)
  98. sheet.readonly_rows(rows=[8], readonly=True, redraw=True)
  99. sheet.readonly_rows(rows=[9], readonly=True, redraw=True)
  100. sheet.readonly_rows(rows=[10], readonly=True, redraw=True)
  101. sheet.readonly_columns(columns=[4], readonly=True, redraw=True)
  102. # sheet.readonly_columns(columns=[5], readonly=True, redraw=True)
  103. sheet.readonly_columns(columns=[6], readonly=True, redraw=True)
  104. test_list = ["избери !", "Обект Асеновград", "Обект Пловдив", "Обект Брацигово", "Доставчици", "Клиенти", "Нов шанс ЕООД"]
  105. sheet.dropdown_cell(4, 5, test_list)
  106.  
  107. top.mainloop()
Add Comment
Please, Sign In to add comment