簡體   English   中英

Tkinter Tix清單Hlist標題配置選項

[英]Tkinter Tix Checklist Hlist Header Configuration Options

我希望tcl / tk專家可以幫助回答有關Tix CheckList Hlist Header的超級利基問題。 我要做的就是將背景顏色從難看的灰色更改為白色。

我發現很難知道我可以在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']

我不知道如何對實際的標頭對象執行此操作,以查看可用的選項。

看起來是這樣的:

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

但我試過了: backgroundselectbackgroundbgcolor等等。 它們都以相同的_tkinter.TclError: unknown option "-NAMEHERE"消息。

只需將headerbackground參數添加到header_create()方法即可:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM