[Tkinter-discuss] Maybe a bug about tk.Text and tk.Label

Michael Lange klappnase at web.de
Mon May 8 04:27:55 EDT 2023


Hi,

On Sun, 7 May 2023 08:34:29 +0800 (CST)
张小平 <13295564836 at 163.com> wrote:

> When i use Text or Label to show  this :
> [
> [1,"PAGE",{"id":"w"}],
> [2,"Text",{"caption":"This is first GUI Page,totally different form
> HTML."}] ]
>
>
> It shows this:
> {1 PAGE {{'id': 'w'}}} {2 Text {{'caption': 'This is first GUI Page,
> totally different form HTML.'}}}
>

you mean if you pass the list directly to the Label's text option?
In this case, the "magic" of tkinter apparently converts the Python list
into a proper Tcl list which is what you see here.
If you want the Python list to be displayed as label text, you need to
enclose it in quotation marks, as in

s = '''[
[1,"PAGE",{"id":"w"}],
[2,"Text",{"caption":"This is first GUI Page,totally different form
HTML."}] ]'''
Label(parent, text=s, justify='left')

Have a nice day,

Michael


More information about the Tkinter-discuss mailing list