Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select a single row of a list box in PySimpleGUI

My question is simple, I'm a begginer in PySimpleGUI, and I want to know how do I change the color of text in a list box, but i want to change only some specific lines, so it's important that I can run all the list and select the lines. Someone know how to do that, I'll be very thankfull.

like image 855
Mateus Coelho Avatar asked Nov 16 '25 05:11

Mateus Coelho


1 Answers

tkinter code required to set options for items in listbox.

enter image description here

import PySimpleGUI as sg

sg.theme("DarkBlue")

items = ['USA', 'Mexico', 'Japan', 'Korea', 'UK', 'China', 'France']
asia_index = (2 ,3, 5)

layout = [
    [sg.Listbox(items, size=(10, 7), key='-LISTBOX-')],
]
window = sg.Window('Title', layout, finalize=True)
listbox = window['-LISTBOX-'].Widget
for index in asia_index:
    listbox.itemconfigure(index, bg='green', fg='white')    # set options for item in listbox
while True:
    event, values = window.read()
    if event == sg.WINDOW_CLOSED:
        break
    print(event, values)

window.close()
like image 166
Jason Yang Avatar answered Nov 17 '25 17:11

Jason Yang



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!