[Tkinter] [split] Is there a way to embed a treeview as a row inside another treeview? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: [Tkinter] [split] Is there a way to embed a treeview as a row inside another treeview? (/thread-35305.html) |
[split] Is there a way to embed a treeview as a row inside another treeview? - CyKlop - Oct-18-2021 Now comes the next question, this time regarding tkinter.ttk.Treeview Is there a way to embed a treeview as a row inside another treeview? The reason I ask is that the structures I want to show inside the (outer) treeview look like this: +---------------+--------------+-------------------+ |Project Name | Start Date | | +---------------+--------------+ | |[+] Foo | 2021/10/10 | | | +-----------------+--------+----------------+ | | | Name | Emp ID | Department | | | +-----------------+--------+----------------+ | | | Marlon Brando | 00001 | Public Affairs | | | | James Dean | 00002 | Accounting | | | | Elvis Presely | 01467 | Liasion | | | +-----------------+--------+----------------+ | |[+] Bar | 2021/12/25 | | | +-----------------+--------+----------------+ | | | Name | Emp ID | Department | | | +-----------------+--------+----------------+ | | | Charlie Chaplin | 02001 | Public Affairs | | | | Larry | 02002 | Woodshop | | | | Curly | 02467 | Painting | | | +-----------------+--------+----------------+ | etcIt appears that Treeview can only handle homogenous rows, unfortunately. I know I could do it like this: +---------------+------------+---------------+--------+----------------+ | Project Name | Start Date | Name | Emp ID | Department | |[+] Foo | 2021/10/10 | | | | | | | Marlon Brando | 00001 | Public Affairs | | | | James Dean | 00002 | Accounting | | | | Elvis Presely | 01467 | Liasion | etcbut that doesn't work well if there are more than a couple of fields for both the outer and subordinate rows. I guess this is more a tkinter question than a python question, but I'm hoping someone can give me a start at the above -- much as you all straighened out my misapprehension about the list.remove() thing (which is solved, by the way -- thank you!) RE: [split] Is there a way to embed a treeview as a row inside another treeview? - CyKlop - Oct-19-2021 I've been going through the documentation and I'm starting to think I'll have to do some sort of custom widget to do this, darn it :/ RE: [split] Is there a way to embed a treeview as a row inside another treeview? - Larz60+ - Oct-19-2021 Take a look at: https://stackoverflow.com/a/57039335 Is this what you are trying to do? RE: [split] Is there a way to embed a treeview as a row inside another treeview? - CyKlop - Oct-19-2021 (Oct-19-2021, 03:33 PM)Larz60+ Wrote: Take a look at: https://stackoverflow.com/a/57039335 Can't quite say. Assume I have two classes: # yeah, I know these should be dataclasses. This is just a fast example. class Member: def __init__(self, *, name: Optional[str] = None, office: Optional[Position] = None, joined: Optional[datetime] = None, dues_paid: bool = False, phone: Optional[str] = None, address: Optional[str] = None, city: Optional[str] = None, province: Optional[str] = None): self.name = name self.office = office self.joined = joined self.dues_paid = dues_paid self.phone = phone self.address = address self.city = city self.province = province class Chapter(list): def __init__(self, *, name: str, address: str, phone: str, officers: Optional[List[Member]] = None, members: Optional[List[Member]], founded: Optional[datetime] = None, motto: Optional[str], national_dues_paid: bool = False): self.name = name self.address = address self.phone = phone if officers is None: self.officers = list() else: self.officers = officers if members is None: self.members = list() else: self.members = members self.founded = founded self.motto = motto self.dues_paid = national_dues_paid chapters = list() # Will hold a list of chaptersNote that the above is a fast hack done here in the editor to convey the flavour of what I want. It's not what I'm writing (which is a lot more complex) nor guaranteed to be working nor even good python-fu. What I would like to do is display a treeview of chapters and their members, with all the data from a chapter being displayed. When the chapter is expanded, all the officers and then the members are displayed as a child of the chapter. Thus it would look something like: --------------+--------+----------------+-----------------------+---------------------+------------------+ Chapter | Status | Phone Number | Address | City | Country | --------------+--------+----------------+-----------------------+---------------------+------------------+ [+] Chapter 1 | Paid | (555) 555-1212 | 1313 Mockingbird Lane | Monsterville | Never-Never Land | ------------------+----------------+----------------+--------+--------------+-------------+ Name | Office | Phone | Status | Member Since | Country | ------------------+----------------+----------------+--------+--------------+-------------+ Peter Pan | President | (555) 555-1213 | Paid | Dec 12, 1941 | Fantasyland | Tiger Lilly | Vice-President | (555) 555-1214 | Paid | Jul 20, 1969 | Fantasyland | ------------------+----------------+----------------+--------+--------------+-------------+ [+] Chapter 2 | | (501) 555-1212 | P.O. Box 12727 | Langley, Virginia | USA | ------------------+----------------+----------------+--------+--------------+-------------+ Name | Office | Phone | Status | Member Since | Country | ------------------+----------------+----------------+--------+--------------+-------------+ Loch Ness Monster | President | (555) 555-1215 | Paid | Nov 11, 1918 | Loch Ness | Bigfoot | | (555) 555-1216 | | Sep 2, 1945 | Colorado | Yeti | | (555) 555-1217 | | Oct 4, 1957 | Tibet | ------------------+----------------+----------------+--------+--------------+-------------+ --------------+--------+----------------+-----------------------+---------------------+------------------+So, basically, it's a treeview where I want to show different column headings and column widths (and column formatting) for the child nodes (and a different number of columns) RE: [split] Is there a way to embed a treeview as a row inside another treeview? - deanhystad - Oct-19-2021 I am not used to seeing column headings for hierarchical information. I think that would be confusing. RE: [split] Is there a way to embed a treeview as a row inside another treeview? - CyKlop - Oct-20-2021 (Oct-19-2021, 11:32 PM)deanhystad Wrote: I am not used to seeing column headings for hierarchical information. I think that would be confusing. The problem is, of course, that it is displaying a list, each item of which is ALSO a list, and the two lists are heterogenous (radically different shapes). Do you have a better idea how to display this? Although I've done some Python coding, I'm a neophyte at Tk. Perhaps there's a better widget for this? |