栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

是否可以为列表框小部件中的特定项目着色?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

是否可以为列表框小部件中的特定项目着色?

根据

effbot.org
有关
Listbox
小部件的文档,您不能更改特殊项目的颜色:

列表框只能包含文本项,并且所有项必须具有相同的字体和颜色

但是实际上,您可以使用对象的

itemconfig
方法来更改特定项目的字体和背景色
Listbox
。请参见以下示例:

import tkinter as tkdef 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()


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/652765.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号