我希望tcl/tk专家能够帮助回答这个关于Tix CheckList Hlist报头的超级小众问题。我想做的就是把背景颜色从丑陋的灰色改为白色。
我甚至很难知道我可以在tix中使用什么选项(cnf={}或**kw)。我发现我可以执行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']我不知道如何对实际标头对象执行此操作,以查看哪些选项可用。
看上去是这样的:

下面是创建它的代码:
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"消息结束。
发布于 2016-09-12 07:43:15
简单地说,将headerbackground参数添加到header_create()方法:
...
self.checklist.hlist.header_create(0, itemtype=tix.TEXT, text='My Heading Text',
headerbackground="red", relief='flat')
...https://stackoverflow.com/questions/39441438
复制相似问题