Advertisement
ALEXANDAR_GEORGIEV

table_test

Nov 28th, 2022
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.60 KB | Source Code | 0 0
  1. import tkinter as tk
  2.  
  3. title = tk.Tk()
  4. title.title('Нематериални активи')
  5. title.geometry('400x200+200+150')  # 1060
  6. title.resizable(True, True)
  7. title.attributes('-topmost', 'true')
  8.  
  9. col_0 = col_1 = col_2 = col_3 = col_4 = dict
  10. row_0 = row_1 = row_2 = row_3 = dict
  11. val_0 = val_1 = val_2 = val_3 = val_4 = tk.Label()
  12. #           col_0       col_1     col_2   col_3   col_4
  13. #          --------------------------------------------
  14. #  row_0: показатели | Ant_1    | Ant_2 | Ant_3 | Ant_4
  15. #  row_1: dma        | 200      | 300   | 400   | 500
  16. #  row_2: dna        | 20       | 30    | 40    | 50
  17. #  row_3: dfa        | 2        | 3     | 4     | 5
  18.  
  19. da = {'row_0': {'col_0': {'val_0': 'Показатели'}, 'col_1': {'val_1': 'Ant_1'}, 'col_2': {'val_2': 'Ant_2'}, 'col_3': {'val_3': 'Ant_3'}, 'col_4': {'val_4': 'Ant_4'}},
  20.       'row_1': {'col_0': {'val_0': 'dma'}, 'col_1': {'val_1': '200'}, 'col_2': {'val_2': '300'}, 'col_3': {'val_3': '400'}, 'col_4': {'val_4': '500'}},
  21.       'row_2': {'col_0': {'val_0': 'dna'}, 'col_1': {'val_1': '20'}, 'col_2': {'val_2': '30'}, 'col_3': {'val_3': '40'}, 'col_4': {'val_4': '50'}},
  22.       'row_3': {'col_0': {'val_0': 'dfa'}, 'col_1': {'val_1': '2'}, 'col_2': {'val_2': '3'}, 'col_3': {'val_3': '4'}, 'col_4': {'val_4': '5'}}
  23.       }
  24.  
  25. count_row = len(da)
  26. count_col = len(da['row_0'])
  27. print('count_row: ', count_row)
  28. print('count_col: ', count_col)
  29. # print(da['row_0']['col_0']['val_0'])
  30. def create_label(text, row_x, col_y):
  31.       label = tk.Label(title, text=text, font=('Times New Roman', 12, 'bold'), bg='white', height=1,
  32.                     anchor='center', fg='black', justify='center')
  33.       label.grid(row=row_x, column=col_y, padx=(10, 10), pady=(10, 10), sticky='nswe')
  34.  
  35.  
  36. def create_table():
  37.       row_n = 0
  38.       for row in da:  # Редове
  39.             col_n = 0
  40.             for column in da[row]:  # Колони
  41.                   for val in da[row][column]:
  42.                         # print('text: ', da[row][column][val])
  43.                         text = da[row][column][val]
  44.                         create_label(text=text, row_x=row_n, col_y=col_n)
  45.                         col_n += 1
  46.             row_n += 1
  47.  
  48. create_table()
  49.  
  50.  
  51.  
  52.  
  53.  
  54.                   # create_label(text=da[row][column][val])
  55.  
  56.  
  57.  
  58.  
  59. title.mainloop()
  60.  
  61.  
  62.  
  63. # def create_label(text, row_x, col_y):
  64. #       label = tk.Label(title, text=text, font=('Times New Roman', 12, 'bold'), bg='white', height=5,
  65. #                     anchor='center', fg='black', justify='center')
  66. #       label.grid(row=row_x, column=col_y, padx=(10, 10), pady=(10, 10), sticky='nswe')
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement