使用复选框创建树视图

编程入门 行业动态 更新时间:2024-10-24 03:25:10
本文介绍了使用复选框创建树视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在尝试基于以下使用示例(如何在 Python 中创建带有复选框的树视图).

I am trying to build an application based on the following usage example (How to create a tree view with checkboxes in Python).

此示例使用 Tix 库构建带有复选框的 Treeview.However, when I run this example, whenever a Checkbox is checked, the text label of that box disappears.

This example builds a Treeview with checkboxes using the Tix library. However, when I run this example, whenever a Checkbox is checked, the text label of that box disappears.

有人能帮我避免上面提到的行为吗?

Could someone help me to avoid the behaviour mentioned just above?

import Tix

class View(object):
    def __init__(self, root):
        self.root = root
        self.makeCheckList()

    def makeCheckList(self):
        self.cl = Tix.CheckList(self.root, browsecmd=self.selectItem)
        self.cl.pack()
        self.cl.hlist.add("CL1", text="checklist1")
        self.cl.hlist.add("CL1.Item1", text="subitem1")
        self.cl.hlist.add("CL2", text="checklist2")
        self.cl.hlist.add("CL2.Item1", text="subitem1")
        self.cl.setstatus("CL2", "on")
        self.cl.setstatus("CL2.Item1", "on")
        self.cl.setstatus("CL1", "off")
        self.cl.setstatus("CL1.Item1", "off")
        self.cl.autosetmode()

    def selectItem(self, item):
        print item, self.cl.getstatus(item)

def main():
    root = Tix.Tk()
    view = View(root)
    root.update()
    root.mainloop()

if __name__ == '__main__':
    main()

推荐答案

问题是选择的默认前景色与背景色相同.问题通过在self.cl初始化后添加如下代码行解决:

The problem is that the default foreground color on selection is the same as the background color. The problem is resolved by adding the following line of code after the initialization of self.cl:

self.cl.hlist.config(selectforeground="black")

这篇关于使用复选框创建树视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-30 05:59:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1390203.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视图   复选框

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!