I recently found PySimpleGUI. At the time looked like it could save me a lot of work.
I wanting to create a 'tagger' for jpeg images using PySimpleGUI as the interface.
I have a long list of tag-words in a simple python list.
I have had some success as I can create a row of checkboxes, but not a column.
My initial research found a generator to use to make many checkboxes.
My goal is to have 3 columns filled with list generated chackboxes.
Generator Snippet
I found this snippet of code to generate the buttons from this PySimpleGUI page. Then modified for checkboxes. I have working functions, but I can't format the construct them to a column.
def CBtn(BoxText):
return sg.Checkbox(BoxText, size=(8, 1), default=False)
column2 = sg.Column([[sg.Text('User Id:')], [CBtn(Bx) for Bx in Tags1]])
Main Code
#!/usr/bin/env python3
import PySimpleGUI as sg
sg.theme('Dark Red')
TaggerList = ["viking", "saddle", "beast", "ze", "princess", "vet", "art", "two", "hood", "mosaic",
"viking1", "saddle1", "beast1", "ze1", "princess1", "vet1", "art1", "two1", "hood1", "mosaic1"]
TaggerListLen = len(TaggerList)
Tags1 = TaggerList[:int(TaggerListLen/3)]
Tags2 = TaggerList[int(TaggerListLen/3):int(TaggerListLen/3*2)]
Tags3 = TaggerList[int(TaggerListLen/3*2):]
def CBtn(BoxText):
return sg.Checkbox(BoxText, size=(8, 1), default=False)
column2 = [[sg.Text('Column 2', justification='center', size=(10, 1))], [CBtn(Bx) for Bx in Tags2]]
column5 = sg.Column([[sg.Checkbox("BoxText1", size=(8, 1), default=False)],
[sg.Checkbox("BoxText2", size=(8, 1), default=False)],
[sg.Checkbox("BoxText3", size=(8, 1), default=False)],
[sg.Checkbox("BoxText4", size=(8, 1), default=False)]])
layout = [
[sg.Menu(menu_def, tearoff=True)],
[sg.Text('Image Tagger', size=(
30, 1), justification='center', font=("Helvetica", 25), relief=sg.RELIEF_RIDGE)],
[sg.Text('Your Folder', size=(15, 1), justification='right'),
sg.InputText('Default Folder'), sg.FolderBrowse()],
[sg.Column(column2)]
[column5]
window = sg.Window('Everything bagel', layout)
Shown in the screen capture the generated checkboxes are set in a row and not a column. So sg.Column(column2)
is a row. When I manually add the checkboxes for column5
I get a proper column.
Format
When I use the generator definition I get this: [CBtn('1'), CBtn('2'), CBtn('3'), CBtn('log'), CBtn('ln'), CBtn('-')],
I'm looking for something like this: [[CBtn('1')], [CBtn('2')], [CBtn('3')], [CBtn('log')], [CBtn('ln')], [CBtn('-')]],
As this follows the manual column5 format.
I've have tried many variations of the generator and def
without much success.
Here is an example of my attempts to achieve the format above.
column1 = [[sg.Text('Column 1', justification='center', size=(10, 1))], [BaseTag.append([CBtn(Bx)]) for Bx in Tags1]]
But I get a AttributeError: 'NoneType' object has no attribute 'ParentContainer'
Final
This was suppose to be easy. I guess, I'm bending the framework too much. PySimplegui looked good, but after hours of no head way, I wonder.