Reputation: 532
I'm trying to show a json in my gui but right now it looks like this:
I want it to be properly formated. I've tried using this :
json_text = StringVar()
json_formatted = json.dumps(data, indent=4, sort_keys=True)
json_text.set(json_formatted)
It worked when I printed it but not in my gui I've also tried using:
test_json_text = Label(o_canvas_l, anchor='w', textvariable=json_text)
test_json_text.grid(column=0, row=0, sticky=W)
Upvotes: 0
Views: 278
Reputation: 28708
For multiline text the Message
widget is better than Label
. Set anchor="w"
to make the text left-aligned. Unfortunately, it wraps long lines. The Text
widget also works, it's left-aligned by default, and its text wrapping can be turned off. I would use something like:
text = tk.Text(frame, wrap=tk.NONE)
text.insert(tk.END, "before\nhello, world lorem ipsum\nafter")
text.configure(state="disabled")
text.pack()
Upvotes: 1