Mateus Coelho
Mateus Coelho

Reputation: 50

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.

Upvotes: 4

Views: 3609

Answers (2)

Jason Yang
Jason Yang

Reputation: 13061

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()

Upvotes: 4

Kfir Ram
Kfir Ram

Reputation: 334

You can change the color of a text by adding text_color='COLOR' when creating it.

for exmaple:

Sg.Text("My text", key="sub_title", size=(15, 1), text_color='yellow')

And if you want to change the color of a button you'll need to use button_color=('FIRST_COLOR', 'SECOND_COLOR') just like below:

    Sg.Button("Update", key='update_button', size=(25, 1), button_color=('blue', 'purple'))

Enjoy.

Upvotes: 1

Related Questions