Tkinter Tix Checklist Hlist Header Configuration Options

By : Jarad
Source: Stackoverflow.com
Question!

I'm hoping a tcl/tk expert can help answer this super-niche question regarding a Tix CheckList Hlist Header. All I want to do is change the background color from an ugly gray to white.

I find it very difficult to even know what options (cnf={} or **kw) I can use for ANYTHING in tix. I have discovered that I can do self.checklist.hlist.config().keys() which returns:

['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']

I don't know how to do this for the actual header object to see what options are available.

This is what it looks like:

Tix CheckList Hlist Header

Here's the code that creates it:

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()

Additional info:

By the way, I'm mainly using this site to figure out what methods are available for hlist - http://epydoc.sourceforge.net/stdlib/Tix.HList-class.html

This example was helpful too: https://svn.python.org/projects/stackless/trunk/Demo/tix/samples/SHList2.py

What Have I Tried...

Lots of things for hours on-end. I think this should be in:

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

but I've tried: background, selectbackground, bg, color ... and more. They all end with the same _tkinter.TclError: unknown option "-NAMEHERE"message.

By : Jarad


Answers

Simply, add headerbackground parameter to header_create() method:

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


This video can help you solving your question :)
By: admin