5
Listbox
위젯의 특정 요소를 언급하고 있습니다.목록 상자 위젯에서 특정 항목의 색상을 지정할 수 있습니까?
배경에 색칠하는 것이 가장 바람직하지만 특정 세포에 색칠하는 것은 환상적입니다.
Listbox
위젯의 특정 요소를 언급하고 있습니다.목록 상자 위젯에서 특정 항목의 색상을 지정할 수 있습니까?
배경에 색칠하는 것이 가장 바람직하지만 특정 세포에 색칠하는 것은 환상적입니다.
Listbox
위젯은 spefic 항목의 색상은 변경할 수 없습니다 관한 effbot.org
문서에 따르면 : 목록 상자는 텍스트 항목을 포함 할 수 있습니다
이 있어야합니다을, 모든 아이템이 같은 글꼴과 색상
실제로 Listbox
개체의 itemconfig
메서드를 사용하여 특정 항목의 글꼴과 배경색을 모두 변경할 수 있습니다. 다음 예를 참조하십시오.
import tkinter as tk
def demo(master):
listbox = tk.Listbox(master)
listbox.pack(expand=1, fill="both")
# inserting some items
listbox.insert("end", "A list item")
for item in ["one", "two", "three", "four"]:
listbox.insert("end", item)
# this changes the background colour of the 2nd item
listbox.itemconfig(1, {'bg':'red'})
# this changes the font color of the 4th item
listbox.itemconfig(3, {'fg': 'blue'})
# another way to pass the colour
listbox.itemconfig(2, bg='green')
listbox.itemconfig(0, foreground="purple")
if __name__ == "__main__":
root = tk.Tk()
demo(root)
root.mainloop()
아 ... 감사합니다. 저는 파이썬에 익숙하지 않고 .configure (bg = "Green")를 사용하려고했습니다. –