thecurious
thecurious

Reputation: 41

How to create a scroll with many checkboxes in pysimplegui?

I'm trying to create a GUI with PySimpleGUI that contains many checkboxes with a scroll to the right to it that allows me to move around. I want my GUI to maintain its size by many checkboxes that have.

This is my code:

form = sg.FlexForm("Dynamic Combo")
layout = [[sg.Text('<-- Enlazar Clientes con Páginas web -->')],
    [sg.Text('Dominio: ')], [sg.InputText()],
    [sg.Text('URL del Cliente: (con http:// o https://)')], [sg.InputText()],
    [sg.Button("SELECCIONAR TODOS")], 
    [sg.Checkbox("something")], [sg.Checkbox("something")],
    [sg.Checkbox("something")], [sg.Checkbox("something")],
    [sg.Checkbox("something")], [sg.Checkbox("something")],
    [sg.Checkbox("something")], [sg.Checkbox("something")],
    [sg.Checkbox("something")], [sg.Checkbox("something")],
    [sg.Checkbox("something")], [sg.Checkbox("something")],
    [sg.Checkbox("something")], [sg.Checkbox("something")],
    [sg.Checkbox("something")], [sg.Checkbox("something")],
    [sg.Checkbox("something")], [sg.Checkbox("something")],
    [sg.Checkbox("something")], [sg.Checkbox("something")],
    [sg.Checkbox("something")], [sg.Checkbox("something")],
    [sg.Checkbox("something")], [sg.Checkbox("something")],
    [sg.Checkbox("something")], [sg.Checkbox("something")],
    [sg.Text('')],
    [sg.Submit('Ejecutar'), sg.Cancel('Salir')]
]

form = sg.Window('Enlazador de Páginas Web').Layout(layout)

How can I do it? I've heard that sg.Column allows me something similar, but I've tried to implement it and I have not achieved anything.

Upvotes: 4

Views: 7388

Answers (2)

thecurious
thecurious

Reputation: 41

This is my code now that I have made the corrections and improvements. I hope it serves you:

import PySimpleGUI as sg, sys

form = sg.FlexForm("Dynamic Combo")
col = [[sg.Checkbox("something1",key=1)], [sg.Checkbox("something2",key=2)],
    [sg.Checkbox("something3",key=3)], [sg.Checkbox("something4",key=4)],
    [sg.Checkbox("something5",key=5)], [sg.Checkbox("something6",key=6)],
    [sg.Checkbox("something7",key=7)], [sg.Checkbox("something8",key=8)],
    [sg.Checkbox("something9",key=9)], [sg.Checkbox("something10",key=10)],
    [sg.Checkbox("something11",key=11)], [sg.Checkbox("something12",key=12)],
    [sg.Checkbox("something13",key=13)], [sg.Checkbox("something14",key=14)],
    [sg.Checkbox("something15",key=15)], [sg.Checkbox("something16",key=16)],
    [sg.Checkbox("something17",key=17)], [sg.Checkbox("something18",key=18)]]
layout = [[sg.Text('<-- Scroll with Checkbox -->')],
    [sg.Button("SELECT ALL")], [sg.Button("DESELECT ALL")], 
    [sg.Column(col, size=(300,300), scrollable=True)],
    [sg.Cancel('Exit')]
]

form = sg.Window('Checkbox practice').Layout(layout)

while True:
    event, values = form.Read()
    if event == "SELECT ALL":  
        # IN THE RANGE ALWAYS PUT A NUMBER MORE TO GET THAT NUMBER
        for x in range(1,19):
            form.FindElement(x).Update(True)
    if event == "DESELECT ALL":  
         # IN THE RANGE ALWAYS PUT A NUMBER MORE TO GET THAT NUMBER
        for x in range(1,19):
            form.FindElement(x).Update(False)
    if event == "Exit":
        sys.exit()

I thought that if I had a single button to select and deselect everything, and that its name would change depending on what I press would be a good idea. I am studying it, although I have not found it yet. If someone knows that you comment, please. If I learn to do it I will upload the answer. Thank you

Upvotes: 0

Mike from PSG
Mike from PSG

Reputation: 5754

You are correct that you can place the layout inside of a Column Element in order to get scroll bars.

Try changing your last line of code to this. It will make your window smaller and add scrollbars. Read more on the parameters available to the Column element.

form = sg.Window('Enlazador de Páginas Web').Layout([[sg.Column(layout, size=(300,300), scrollable=True)]])
form.Read()

Upvotes: 6

Related Questions