Select PySimpleGUI 中单行列表框
Select a single row of a list box in PySimpleGUI
我的问题很简单,我是 PySimpleGUI 的初学者,我想知道如何更改列表框中文本的颜色,但我只想更改某些特定的行,所以重要的是我可以 运行 所有列表和 select 行。
有人知道怎么做,我会非常感谢。
您可以通过在创建文本时添加 text_color='COLOR' 来更改文本的颜色。
例如:
Sg.Text("My text", key="sub_title", size=(15, 1), text_color='yellow')
如果您想更改按钮的颜色,您需要使用 button_color=('FIRST_COLOR', 'SECOND_COLOR' ) 如下所示:
Sg.Button("Update", key='update_button', size=(25, 1), button_color=('blue', 'purple'))
尽情享受吧。
为列表框中的项目设置选项所需的 tkinter 代码。
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()
我的问题很简单,我是 PySimpleGUI 的初学者,我想知道如何更改列表框中文本的颜色,但我只想更改某些特定的行,所以重要的是我可以 运行 所有列表和 select 行。 有人知道怎么做,我会非常感谢。
您可以通过在创建文本时添加 text_color='COLOR' 来更改文本的颜色。
例如:
Sg.Text("My text", key="sub_title", size=(15, 1), text_color='yellow')
如果您想更改按钮的颜色,您需要使用 button_color=('FIRST_COLOR', 'SECOND_COLOR' ) 如下所示:
Sg.Button("Update", key='update_button', size=(25, 1), button_color=('blue', 'purple'))
尽情享受吧。
为列表框中的项目设置选项所需的 tkinter 代码。
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()