Note that there are some explanatory texts on larger screens.

plurals
  1. POPython : Display a Dict of Dicts using a UI Tree for the keys and any other widget for the values
    primarykey
    data
    text
    <p>I have three dicts, one providing a list of all the available options, and two providing a subset of choices (one set for defaults and one for user choices). I get the three dicts using python's built in JSON parser.</p> <p>I want display, in a UI, a tree on the left that is based on the keys in the dicts, on the right I would like to display either a combobox, a button, a listbox or some other appropriate widget to manipulate the data for that key. I need the tree since I'm really working with a dict of dicts and I want to allow folding.</p> <p>So far I have looked into tkinter, tkinter's ttk and tix libraries and they allow trees but don't allow configurable lists on the right it seems. I've also seen some examples where the tree is borrowed from python's IDLE. </p> <ol> <li>Is there a GUI toolkit that provides such functionality or is there no such thing and I have to design my own ?</li> <li>If I have to design my own is there any GUI toolkit that you would recommend over tk ?</li> <li>Is there a basic tutorial on GUI design for the recommended toolkit if it doens't provide this kind of thing ?</li> </ol> <p>I'd prefer it if the GUI toolkit was cross platform compatible (*nix and win) and free to distribute if possible. Out of interest is there a tutorial on creating custom widgets with tk, I have tried looking but I keep getting directed to tk's widget use instead of widget design :s </p> <p>As a minimal example I've dropped the extra dicts for now and have the following : </p> <pre><code>import json import tkinter as tk from tkinter import ttk from pprint import pprint as pprint def JSONTree(Tree, Parent, Dictionery, TagList = []): for key in Dictionery : if isinstance(Dictionery[key],dict): Tree.insert(Parent, 'end', key, text = key) TagList.append(key) JSONTree(Tree, key, Dictionery[key], TagList) pprint(TagList) elif isinstance(Dictionery[key],list): Tree.insert(Parent, 'end', key, text = key) # Still working on this else : Tree.insert(Parent, 'end', key, text = key, value = Dictionery[key]) if __name__ == "__main__" : # Setup the root UI root = tk.Tk() root.title("JSON editor") root.columnconfigure(0, weight=1) root.rowconfigure(0, weight=1) # Setup Data Data = {"firstName": "John", "lastName": "Smith", "gender": "man", "age": 32, "address": {"streetAddress": "21 2nd Street", "city": "New York", "state": "NY", "postalCode": "10021"}, "phoneNumbers": [{ "type": "home", "number": "212 555-1234" }, { "type": "fax", "number": "646 555-4567" }]} # Setup the Frames TreeFrame = ttk.Frame(root, padding = "3") TreeFrame.grid(row = 0, column = 0, sticky = tk.NSEW) # Setup the Tree tree = ttk.Treeview(TreeFrame, columns = ('Values')) tree.column('Values', width = 100, anchor = 'center') tree.heading('Values', text = 'Values') JSONTree(tree, '', Data) tree.pack(fill=tk.BOTH, expand = 1) # Limit windows minimum dimensions root.update_idletasks() root.minsize(root.winfo_reqwidth(),root.winfo_reqheight()) root.mainloop() </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload