-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjson_gui.py
More file actions
50 lines (37 loc) · 1.56 KB
/
json_gui.py
File metadata and controls
50 lines (37 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from tkinter import *
from tkinter import filedialog
from json_cli import json_cli
class json_gui(json_cli):
def __init__(self):
self.main_window = Tk()
self.row = 0
self.filename = StringVar()
self.main_frame= Frame(self.main_window)
Entry(self.main_frame, textvariable=self.filename).pack(side="left",fill="x")
Button(self.main_frame,text = "Browse", command = self.browse_file).pack(side="left")
Button(self.main_frame,text = "Show", command = self.show_file).pack(side="left")
self.main_frame.pack(side="top", fill="x")
return
def browse_file(self):
filename = filedialog.askopenfilename(title = "Select file",
filetypes = (("json", "*.json"),("All files", "*.*")))
self.filename.set(filename)
self.main_frame.pack(side="top", fill="x")
return
def render(self, level, type, key, value, path):
label_name = "{}: {}({}): {}".format(level, path, type, value)
Label(self.data_frame,text=label_name).pack()
self.data_frame.pack(fill="x")
return
def dump(self):
#TODO Get the values from the child entry fields of the dataframe
self.dump_file(str(self.filename))
def show_file(self):
if hasattr(self, 'data_frame'):
self.data_frame.destroy()
self.data_frame = Frame(self.main_window)
self.load_file(self.filename.get())
return
if __name__ == '__main__':
clas = json_gui()
clas.main_window.mainloop()