Python 在';佐特罗'-喜欢时尚,用Tkinter

Python 在';佐特罗'-喜欢时尚,用Tkinter,python,json,tkinter,Python,Json,Tkinter,因此,我有JSON文件形式的数据,如下所示: json = { "moments": [ { "N1": { "scheme": "NH3_ISA-GRID", "type": "N", "rank": "4", "moments": [ " Q0 Q

因此,我有JSON文件形式的数据,如下所示:

json = {
    "moments": [
        {
            "N1": {
                "scheme": "NH3_ISA-GRID",
                "type": "N",
                "rank": "4",
                "moments": [
                    "          Q0        Q1        Q2        Q3        Q4",
                    "0  -1.064525 -0.000004  0.340138  0.000004  0.047612",
                    "1s       NaN -0.105246 -0.000006 -0.208369  0.000035",
                    "1c       NaN  0.036201 -0.000002 -0.482417  0.000005",
                    "2s       NaN       NaN -0.454872 -0.000004  0.734665",
                    "2c       NaN       NaN  0.383145  0.000003  0.979878",
                    "3s       NaN       NaN       NaN -0.105177 -0.000029",
                    "3c       NaN       NaN       NaN -0.097678  0.000015",
                    "4s       NaN       NaN       NaN       NaN  0.454980",
                    "4c       NaN       NaN       NaN       NaN -0.005097"
                ],
                "file": "/Users/gianluca/Desktop/project/example_molecules/ISA/OUT/NH3_ISA-GRID.mom"
            }
        },
        {
            "H3": {
                "scheme": "NH3_ISA-GRID",
                "type": "HN",
                "rank": "4",
                "moments": [
                    "          Q0        Q1        Q2        Q3        Q4",
                    "0   0.353619 -0.000000  0.022593 -0.000000  0.016054",
                    "1s       NaN -0.020984 -0.000000 -0.010761 -0.000000",
                    "1c       NaN -0.009221 -0.000000  0.007970 -0.000000",
                    "2s       NaN       NaN -0.016711 -0.000000  0.015248",
                    "2c       NaN       NaN  0.016692 -0.000000 -0.009410",
                    "3s       NaN       NaN       NaN  0.003688 -0.000001",
                    "3c       NaN       NaN       NaN  0.025270 -0.000001",
                    "4s       NaN       NaN       NaN       NaN  0.005240",
                    "4c       NaN       NaN       NaN       NaN  0.010030"
                ],
                "file": "/Users/gianluca/Desktop/project/example_molecules/ISA/OUT/NH3_ISA-GRID.mom"
            }
        },
        {
            "H4": {
                "scheme": "NH3_ISA-GRID",
                "type": "HN",
                "rank": "4",
                "moments": [
                    "          Q0        Q1        Q2        Q3        Q4",
                    "0   0.355424  0.013163  0.011901  0.007411 -0.012933",
                    "1s       NaN -0.012893 -0.004149  0.015750  0.008439",
                    "1c       NaN  0.012746 -0.005790  0.003681  0.013541",
                    "2s       NaN       NaN -0.022555  0.004799  0.003075",
                    "2c       NaN       NaN  0.017714  0.020630  0.003709",
                    "3s       NaN       NaN       NaN -0.004436  0.008474",
                    "3c       NaN       NaN       NaN -0.002779  0.008116",
                    "4s       NaN       NaN       NaN       NaN -0.001628",
                    "4c       NaN       NaN       NaN       NaN  0.006952"
                ],
                "file": "/Users/gianluca/Desktop/project/example_molecules/ISA/OUT/NH3_ISA-GRID.mom"
            }
        },
        {
            "H5": {
                "scheme": "NH3_ISA-GRID",
                "type": "HN",
                "rank": "4",
                "moments": [
                    "          Q0        Q1        Q2        Q3        Q4",
                    "0   0.355421 -0.013164  0.011902 -0.007411 -0.012934",
                    "1s       NaN -0.012894  0.004148  0.015751 -0.008440",
                    "1c       NaN  0.012746  0.005790  0.003681 -0.013543",
                    "2s       NaN       NaN -0.022556 -0.004800  0.003076",
                    "2c       NaN       NaN  0.017715 -0.020631  0.003710",
                    "3s       NaN       NaN       NaN -0.004436 -0.008476",
                    "3c       NaN       NaN       NaN -0.002779 -0.008116",
                    "4s       NaN       NaN       NaN       NaN -0.001628",
                    "4c       NaN       NaN       NaN       NaN  0.006953"
                ],
                "file": "/Users/gianluca/Desktop/project/example_molecules/ISA/OUT/NH3_ISA-GRID.mom"
            }
        },
        {
            "N1": {
                "scheme": "NH3_ISA",
                "type": "N",
                "rank": "4",
                "moments": [
                    "          Q0        Q1        Q2        Q3        Q4",
                    "0  -1.064533 -0.000007  0.335373 -0.000034 -0.017676",
                    "1s       NaN -0.130782 -0.000007 -0.990753  0.000019",
                    "1c       NaN  0.044770 -0.000006 -1.404081  0.000034",
                    "2s       NaN       NaN -0.451296 -0.000067  0.804011",
                    "2c       NaN       NaN  0.378061 -0.000150  0.911492",
                    "3s       NaN       NaN       NaN -0.096208  0.000019",
                    "3c       NaN       NaN       NaN -0.714299  0.000027",
                    "4s       NaN       NaN       NaN       NaN  0.441683",
                    "4c       NaN       NaN       NaN       NaN  0.107567"
                ],
                "file": "/Users/gianluca/Desktop/project/example_molecules/ISA/OUT/NH3_ISA.mom"
            }
        },
        {
            "H3": {
                "scheme": "NH3_ISA",
                "type": "HN",
                "rank": "4",
                "moments": [
                    "          Q0        Q1        Q2        Q3        Q4",
                    "0   0.353608 -0.000001  0.008389 -0.000003  0.014938",
                    "1s       NaN -0.020138  0.000001 -0.008956  0.000011",
                    "1c       NaN -0.011952 -0.000002 -0.013778  0.000006",
                    "2s       NaN       NaN -0.042028  0.000005 -0.002432",
                    "2c       NaN       NaN  0.015945  0.000000 -0.035642",
                    "3s       NaN       NaN       NaN  0.005689 -0.000000",
                    "3c       NaN       NaN       NaN -0.000196  0.000006",
                    "4s       NaN       NaN       NaN       NaN -0.014408",
                    "4c       NaN       NaN       NaN       NaN  0.016101"
                ],
                "file": "/Users/gianluca/Desktop/project/example_molecules/ISA/OUT/NH3_ISA.mom"
            }
        },
        {
            "H4": {
                "scheme": "NH3_ISA",
                "type": "HN",
                "rank": "4",
                "moments": [
                    "          Q0        Q1        Q2        Q3        Q4",
                    "0   0.355543  0.014180  0.026525  0.004023 -0.017858",
                    "1s       NaN -0.011466  0.015769 -0.009499  0.004331",
                    "1c       NaN  0.013083  0.007198 -0.009804  0.013932",
                    "2s       NaN       NaN -0.018736 -0.004213 -0.015855",
                    "2c       NaN       NaN  0.025705  0.002607 -0.024676",
                    "3s       NaN       NaN       NaN -0.002677  0.013785",
                    "3c       NaN       NaN       NaN -0.006283  0.005618",
                    "4s       NaN       NaN       NaN       NaN -0.010890",
                    "4c       NaN       NaN       NaN       NaN  0.012265"
                ],
                "file": "/Users/gianluca/Desktop/project/example_molecules/ISA/OUT/NH3_ISA.mom"
            }
        },
        {
            "H5": {
                "scheme": "NH3_ISA",
                "type": "HN",
                "rank": "4",
                "moments": [
                    "          Q0        Q1        Q2        Q3        Q4",
                    "0   0.355539 -0.014183  0.026524 -0.004026 -0.017865",
                    "1s       NaN -0.011466 -0.015768 -0.009489 -0.004317",
                    "1c       NaN  0.013084 -0.007197 -0.009803 -0.013921",
                    "2s       NaN       NaN -0.018737  0.004210 -0.015864",
                    "2c       NaN       NaN  0.025709 -0.002620 -0.024688",
                    "3s       NaN       NaN       NaN -0.002672 -0.013795",
                    "3c       NaN       NaN       NaN -0.006286 -0.005612",
                    "4s       NaN       NaN       NaN       NaN -0.010898",
                    "4c       NaN       NaN       NaN       NaN  0.012263"
                ],
                "file": "/Users/gianluca/Desktop/project/example_molecules/ISA/OUT/NH3_ISA.mom"
            }
        }
    ]
}
正如您所见,有一些明显的、可重复的条目,如“scheme”、“type”、“rank”等,我希望以类似于以下Zotero参考软件的方式显示这些条目(参见图1)。因此,它将使用我的JSON键代替“author”、“title”等


有人能告诉我一些TKinter(或其他GUI库)python食谱的方向吗?注意,我只对图1的右侧感兴趣,即以类似的方式显示JSON的键。此外,我可能只是想得太多了,任何一般性的建议都会很好。

只需迭代您的
json
dict和
grid
一堆
标签。至少你会看到这样的情况:

import tkinter as tk

root = tk.Tk()

json = {...}

num = 0
for item in json["moments"]:
    for k, v in item.items():
        for i,j in v.items():
            tk.Label(root, text=i,width=10,anchor="e",font="Arial 10 bold").grid(row=num,column=0,padx=5,sticky="ne")
            tk.Label(root, text=j if i != "moments" else "\n".join(j),width=65,anchor="w").grid(row=num, column=1,padx=5)
            num+=1
    break

root.mainloop()

干得好,这是一个开始发展的好地方+1.