Add Tix widgets to the Tkinter container
I was using Tkinter in Python 2.7 on Windows 7 and found that I needed to create a popover with a tree-shaped checkbox list. I can’t find this in tkinter or ttk. However, I did find it in Tix’s CheckList widget. I have a standalone working example using Tix, but I don’t know how to add my Tix.CheckList to the ttk that controls my main program. Frame。
Wasn’t I forced to use the Tix framework from scratch?
import Tix
import pandas as pd
import Tkinter as tk
class TreeCheckList(object):
def __init__(self, root):
self.root = root
self.cl = Tix.CheckList(self.root)
self.cl.pack(fill=Tix.BOTH, expand=Tix.YES)
self.cl.hlist.config(bg='white', bd=0, selectmode='none', selectbackground='white', selectforeground='black', drawbranch=True, pady=5)
self.cl.hlist.add('ALL', text='All Messages')
self.cl.hlist.add('ALL. First', text='First')
self.cl.setstatus('ALL. First', "off")
self.cl.hlist.add('ALL. Second', text='Second')
self.cl.setstatus('ALL. Second', "off")
self.cl.autosetmode()
def main():
root = Tix.Tk()
top = Tix.Toplevel(root)
checklist = TreeCheckList(top)
root.update()
top.tkraise()
root.mainloop()
if __name__ == '__main__':
main()
The above code runs in a separate program that uses all Tix widgets. However, when I try to implement it into my large program, I get a TclError: invalid command name "tixCheckList"
To simulate this in standalone mode, I changed the following line:
root = Tix.Tk()
top = Tix.Toplevel(root)
to
root = tk. Tk()
top = tk. Toplevel(root)
I wish I could implement a Tix.Toplevel, put it in tk. Tk() root, but same problem.
Am I only allowed to use the Tix framework when using Tix widgets, or am I misunderstanding something? If anyone had good Tix documentation, I would love anything I could get. It seems that good documentation about it is scarce and far from it. Or is the same feature included in ttk and I just ignored it? This seems to be one of the only things that has been missed.
Solution
I just learned that apparently only root
needs to be a Tix class. Since tk, and therefore ttk, classes seem to be nicely added to the Tix root (since most of them extend the tkinter class), which seems like a “fix”. So my question may have been changed by
root = tk. Tk()
to
root = Tix.Tk()
This does require me to pull Tix into a part of the program that I don’t want to use for wrapping purposes, but I guess there’s no other way.