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.
Asked
Active
Viewed 3,137 times
4
-
You can change the text color for the entire list box with `text_color`. There is no way to change individual rows without going a level deeper (like to tk, but this would vary by OS, so it's not trivial.) – nycynik Feb 26 '21 at 08:50
-
would a multiline with print work? – nycynik Feb 26 '21 at 08:50
2 Answers
3
tkinter code required to set options for items in listbox.
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()

Jason Yang
- 11,284
- 2
- 9
- 23
1
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.

Kfir Ram
- 324
- 1
- 4