Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- from tkinter import ttk
- root = tk.Tk()
- label1 = tk.Label(root, text='Текст ячейки').pack()
- enter1 = tk.Entry(root)
- enter1.pack()
- label2 = tk.Label(root, text='Количество колонок').pack()
- enter2 = tk.Entry(root)
- enter2.pack()
- label3 = tk.Label(root, text='Количество строк').pack()
- enter3 = tk.Entry(root)
- enter3.pack()
- heading = 'Заголовок колонки'
- panel_of_tasks = ttk.Treeview(root, columns=[heading], show='headings')
- panel_of_tasks.heading('#1', text=heading)
- def add_line(rows, cols):
- columns = []
- for i in range(cols):
- columns.append(i)
- panel_of_tasks.config(columns=(columns))
- for i in panel_of_tasks.get_children():
- panel_of_tasks.delete(i)
- for i in range(rows):
- panel_of_tasks.insert('', tk.END, values=([enter1.get() for j in range(cols)]))
- panel_of_tasks.config(height=len(panel_of_tasks.get_children()))
- root.config(height=panel_of_tasks['height'])
- def delList():
- for i in panel_of_tasks.get_children():
- panel_of_tasks.delete(i)
- def saveList():
- with open('list000.csv', 'w', encoding='utf-8') as f:
- for i in panel_of_tasks.get_children():
- for j in panel_of_tasks.item(i)['values']:
- f.write(str(j) + ';')
- f.write('\n')
- button1 = ttk.Button(root, text='Add cells', command=lambda: add_line(int(enter3.get()), int(enter2.get()))).pack()
- button2 = ttk.Button(root, text='Delete', command=lambda: delList()).pack()
- button3 = ttk.Button(root, text='Save', command=lambda: saveList()).pack()
- panel_of_tasks.pack()
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement