Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.17 KB | None | 0 0
  1. import tkinter as tk
  2. from tkinter import ttk
  3.  
  4.  
  5. root = tk.Tk()
  6. label1 = tk.Label(root, text="Текст ячейки").pack()
  7. enter1 = tk.Entry(root)
  8. enter1.pack()
  9. label2 = tk.Label(root, text="Количество колонок").pack()
  10. enter2 = tk.Entry(root)
  11. enter2.pack()
  12. label3 = tk.Label(root, text="Количество строк").pack()
  13. enter3 = tk.Entry(root)
  14. enter3.pack()
  15. heading = 'Заголовок колонки'
  16. panel_of_tasks = ttk.Treeview(root, columns=[heading], show='headings')
  17. panel_of_tasks.heading('#1', text=heading)
  18.  
  19.  
  20. def add_line(rows, cols):
  21.     columns = []
  22.     for i in range(cols):
  23.         columns.append(i)
  24.  
  25.     panel_of_tasks.config(columns=(columns))
  26.    
  27.     for i in panel_of_tasks.get_children():
  28.         panel_of_tasks.delete(i)
  29.  
  30.     for i in range(rows):
  31.         panel_of_tasks.insert('', tk.END, values=([enter1.get() for j in range(cols)]))
  32.    
  33.     panel_of_tasks.config(height=len(panel_of_tasks.get_children()))
  34.     root.config(height = panel_of_tasks['height'])
  35.  
  36.  
  37. ttk.Button(root, text='Add cells', command=lambda: add_line(int(enter3.get()), int(enter2.get()))).pack()
  38.  
  39. panel_of_tasks.pack()
  40. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement