0

我希望 tcl/tk 专家可以帮助回答这个关于Tix CheckList Hlist Header的超级利基问题。我要做的就是将背景颜色从难看的灰色更改为白色。

我什至很难知道我可以将哪些选项(cnf={}**kw)用于 tix 中的任何内容。我发现我可以这样做self.checklist.hlist.config().keys()返回:

['background', 'bd', 'bg', 'borderwidth', 'browsecmd', 'columns', 'command',
 'cursor', 'dragcmd', 'drawbranch', 'dropcmd', 'fg', 'font', 'foreground',
 'gap', 'header', 'height', 'highlightbackground', 'highlightcolor',
 'highlightthickness', 'indent', 'indicator', 'indicatorcmd', 'itemtype',
 'padx', 'pady', 'relief', 'selectbackground', 'selectborderwidth',
 'selectforeground', 'selectmode', 'separator', 'sizecmd', 'takefocus',
 'wideselection', 'width', 'xscrollcommand', 'yscrollcommand']

我不知道如何为实际的标头对象执行此操作以查看可用的选项。

这是它的样子:

Tix CheckList Hlist 标头

这是创建它的代码:

import tkinter as tk
from tkinter import tix

class whatever(tk.Frame):
  def __init__(self, parent):
    super(whatever, self).__init__(parent)
    self.parent = parent

    self.checklist = tix.CheckList(self.parent, browsecmd=self.selectItem,
                                   options='hlist.columns 1', highlightthickness=1,
                                   highlightcolor='#B7D9ED')
    self.checklist.grid(sticky='ew', padx=20)

    self.checklist.hlist.config(bg='white', bd=0, selectmode='none', selectbackground='white',
                                selectforeground='black', drawbranch=True, pady=5, header=True)

    self.checklist.hlist.header_create(0, itemtype=tix.TEXT, text='My Heading Text',
                                       relief='flat')

    self.checklist.hlist.add("CL1", text="checklist1")
    self.checklist.hlist.add("CL1.Item1", text="subitem1")
    self.checklist.setstatus("CL1", "on")
    self.checklist.setstatus("CL1.Item1", "off")

  def selectItem(self, item):
      print(item)

root = tix.Tk()
whatever(root)
root.mainloop()

附加信息

顺便说一句,我主要使用这个站点来找出可用的方法hlist- http://epydoc.sourceforge.net/stdlib/Tix.HList-class.html

这个例子也很有帮助:https ://svn.python.org/projects/stackless/trunk/Demo/tix/samples/SHList2.py

我试过什么...

连续几个小时做很多事情。我认为这应该在:

self.checklist.hlist.header_configure(0, background='white')

但我已经尝试过:background, selectbackground, bg, color... 等等。它们都以相同的_tkinter.TclError: unknown option "-NAMEHERE"信息结束。

4

1 回答 1

2

简单地说,给方法添加headerbackground参数header_create()

...
self.checklist.hlist.header_create(0, itemtype=tix.TEXT, text='My Heading Text', 
headerbackground="red", relief='flat')
...
于 2016-09-12T07:43:15.237 回答