SHARE
TWEET

Untitled

a guest Jan 21st, 2020 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import tkinter as tk
  2. from tkinter import ttk
  3. root = tk.Tk()
  4. label1 = tk.Label(root, text='Текст ячейки').pack()
  5. enter1 = tk.Entry(root)
  6. enter1.pack()
  7. label2 = tk.Label(root, text='Количество колонок').pack()
  8. enter2 = tk.Entry(root)
  9. enter2.pack()
  10. label3 = tk.Label(root, text='Количество строк').pack()
  11. enter3 = tk.Entry(root)
  12. enter3.pack()
  13. heading = 'Заголовок колонки'
  14. panel_of_tasks = ttk.Treeview(root, columns=[heading], show='headings')
  15. panel_of_tasks.heading('#1', text=heading)
  16.  
  17. def add_line(rows, cols):
  18.     columns = []
  19.     for i in range(cols):
  20.         columns.append(i)
  21.     panel_of_tasks.config(columns=(columns))
  22.  
  23.     for i in panel_of_tasks.get_children():
  24.         panel_of_tasks.delete(i)
  25.  
  26.     for i in range(rows):
  27.         panel_of_tasks.insert('', tk.END, values=([enter1.get() for j in range(cols)]))
  28.    
  29.     panel_of_tasks.config(height=len(panel_of_tasks.get_children()))
  30.     root.config(height=panel_of_tasks['height'])
  31.  
  32. def delList():
  33.     for i in panel_of_tasks.get_children():
  34.         panel_of_tasks.delete(i)
  35.  
  36. def saveList():
  37.     with open('list000.csv', 'w', encoding='utf-8') as f:
  38.         for i in panel_of_tasks.get_children():
  39.             for j in panel_of_tasks.item(i)['values']:
  40.                 f.write(str(j) + ';')
  41.             f.write('\n')
  42.  
  43.  
  44. button1 = ttk.Button(root, text='Add cells', command=lambda: add_line(int(enter3.get()), int(enter2.get()))).pack()
  45. button2 = ttk.Button(root, text='Delete', command=lambda: delList()).pack()
  46. button3 = ttk.Button(root, text='Save', command=lambda: saveList()).pack()
  47. panel_of_tasks.pack()
  48. root.mainloop()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top