Tkinter: Changing text in a readonly (!) entry field

Post here if you need help with creating a Graphical User Interface in Python.

Tkinter: Changing text in a readonly (!) entry field

Postby rovf » Fri Aug 16, 2013 4:44 pm

(Python 2.3.5 on Mac OSX 10.4)

I would like to have a widget, where I can display (and update) the text. For the user, the only interaction with the widget should be that the text (or part of it) can be marked with the mouse and copied to the clipboard.

My first idea was to use a Label, but I quickly learned that I can not select/copy from a label.

Googling around, I came accross a suggestion to use an Entry widget instead, but disable it. I tried this suggestion (using state="readonly"), but the documentation says that I can not use the "insert" method, if the widget is disabled. Now I wonder - what other ways do I have to change the text at runtime? Or should I use a completely different widget (maybe a Text widget) for this task?
rovf
 
Posts: 25
Joined: Fri Aug 16, 2013 4:35 pm

Re: Tkinter: Changing text in a readonly (!) entry field

Postby stranac » Fri Aug 16, 2013 6:31 pm

You need to use Tkinter.StringVar as the value of the Entry.
Something like this should work:
Code: Select all
v = Tkinter.StringVar()
entry = Tkinter.Entry(master, textvariable=v, state='readonly')
# ...
v.set('Changed')
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1137
Joined: Thu Feb 07, 2013 3:42 pm

Re: Tkinter: Changing text in a readonly (!) entry field

Postby rovf » Sat Aug 17, 2013 6:50 am

Thanks a lot, I'll try it!
rovf
 
Posts: 25
Joined: Fri Aug 16, 2013 4:35 pm


Return to GUI

Who is online

Users browsing this forum: No registered users and 3 guests