Checklist using Checkbox Treeview → Text creation

Background of code creation

I wanted to write a list of equipment used for youtube videos in the explanation column, Isn't it different for each song?

It would be easy if you could select it with GUI! That's why. image.png

I thought it took a long time to write the code, so I will share it.

Excuse me

--I don't really understand tkinter

--I can't master class

That's why I couldn't play with what was written in class. Let's do our best. You may be able to write it more beautifully, but please close your eyes.

Overview

Go to csv reading → GUI display → Check items to clipboard

The flow.

code

import tkinter as tk
from ttkwidgets import CheckboxTreeview
import pandas as pd
import pyperclip

def list_to_txt(lis_checked_item):
    '''
"I want to store the list in the clipboard with line breaks!"
Arguments: list
    '''
    inst_txt = '\n'.join(lis_checked_item)
    pyperclip.copy(inst_txt)

ttk = tk.ttk
window = tk.Tk()
ct = CheckboxTreeview(window, show='tree') # hide tree headings
ct.pack()

#copy button 
tk.Button(window, text="copy", command=lambda: list_to_txt(ct.get_checked())).pack()

style = ttk.Style(window)

# remove the indicator in the treeview 
style.layout('Checkbox.Treeview.Item', 
             [('Treeitem.padding',
               {'sticky': 'nswe',
                'children': [('Treeitem.image', {'side': 'left', 'sticky': ''}),
                             ('Treeitem.focus', {'side': 'left', 'sticky': '',
                                                 'children': [('Treeitem.text', 
                                                               {'side': 'left', 'sticky': ''})]})]})])

# make it look more like a listbox                                                               
style.configure('Checkbox.Treeview', borderwidth=1, relief='sunken')

# get data
path = "./inst.csv"
inst_data = pd.read_csv(path, sep=',', encoding='shift_jis',header=0)

inst_list = list(inst_data["Model number"].values + " / " + inst_data["Manufacturer"] )

# add items in treeview
for value in inst_list: 
    ct.insert('', 'end', iid = value, text=value)

window.mainloop()

Output result

image.png

Only the checked items are on the clipboard. I want to see the following.

SV-1 88-MR / Korg
Rythm Worf / AKAI 
BeatStep / Arturia

No, it's difficult.

Equipment list csv

image.png

Please enter the model number and manufacturer for the column name. I'm going to read. If you copy and paste, make sure the location is the same as the executable file!

Quote

The article below really helped me. Thank you very much. ttkwidgets Documentation Release 0.11.0 Documentation » ttkwidgets » CheckboxTreeview Python Tkinter Tk support checklist box? How to create selected checkbox list item using Tkinter

that's all.

Recommended Posts

Checklist using Checkbox Treeview → Text creation
Chat creation using sockets
Select features using text data
Text development using Mac services