I created a GUI that represents json file as buttons. I want to make the json structure scrollable. I was able to make it scroll but only up until the middle of the file
import tkinter as tk
import json
class JSONGUI():
json_example = '{"event":{"name":"test","time":"today"}}'
s = '{"success": "true", "status": 200, "message": "Hello"}'
json_example2 = """{
"glossary": {
"title": "example glossary",
"GlossDiv": {
"title": "S",
"GlossList": {
"GlossEntry": {
"ID": "SGML",
"SortAs": "SGML",
"GlossTerm": "Standard Generalized Markup Language",
"Acronym": "SGML",
"Abbrev": "ISO 8879:1986",
"GlossDef": {
"para": "A meta-markup language, used to create markup languages such as DocBook.",
"GlossSeeAlso": ["GML", "XML"]
},
"GlossSee": "markup"
}
}
}
}
}"""
def __init__(self):
json_dict = json.loads(self.json_example2)
#window
self.window = tk.Tk()
self.window.title('JSON GUI')
# self.window.state('zoomed')
self.window.geometry('500x100')
#frame
self.frame = tk.Frame(self.window)
self.frame.grid(column=0, row=0, sticky='W')
self.frame.grid_propagate(False)
#canvas
self.canvas = tk.Canvas(self.frame)
self.canvas.grid(column=0, row=0, sticky='news')
#scrollbar
myscrollbar = tk.Scrollbar(self.window, orient="vertical", command=self.canvas.yview)
myscrollbar.grid(column=1, row=0, sticky='ns')
self.canvas.configure(yscrollcommand=myscrollbar.set)
#json_frame
self.frame_json = tk.Frame(self.canvas)
self.canvas.create_window((0, 0), window=self.frame_json, anchor='nw')
#logic add buttons
self.loop_dict(json_dict, 0, 0)
#others
self.frame.config(width=450, height=50)
self.frame_json.update_idletasks()
self.canvas.config(scrollregion=self.canvas.bbox("all"))
#mainloop
self.window.mainloop()
def test_function(self):
print('button pressed')
def loop_dict(self, json_dict, l, c):
for x in json_dict:
tk.Button(self.frame_json, text=x, command=self.test_function).grid(row=l, column=c, sticky='W')
l += 1
if isinstance(json_dict.get(x), dict):
c += 1
l = self.loop_dict(json_dict.get(x), l, c)
if isinstance(json_dict.get(x), list):
c += 1
l = self.loop_list(json_dict.get(x), l, c)
return l
def loop_list(self, json_list, l, c):
tk.Label(self.frame_json, text='list').grid(row=l, column=c, sticky='W')
l += 1
for x in json_list:
if isinstance(x, dict):
c += 1
l = self.loop_dict(self, x, l, c)
return l
So i am able to scroll but cant scroll further then is shown in the second picture. I noticed if i changed the width and height i was able to scroll a little bit further. What is causing this ? And how can i scroll all the way down ?