How to create a read-only PyGTK text entry?

I am trying to make a widget that contains short text output that the user should be able to copy, but not modify. This is what I came up with:

entry = gtk.Entry() entry.set_property("editable", False) entry.unset_flags(gtk.CAN_FOCUS) 

It works, but the record still looks like it is editable, and it looks bad from the user's point of view. I tried entry.set_sensitive(False) instead, but this prevents copying and makes it completely disabled.

I would like to know how to make the correct read-only text entry that will be inaccessible but still active.

Edit: Here is an image of what I'm talking about, although not GTK (and I work in the GNOME environment).

Edit 2: it starts to look like there is no right way to do this with GTK, if someone can confirm this, I will try to resolve the issue.

+4
source share
3 answers

You can use Label , which can also be selected in wrapping mode (if the text was more than one line)

 label = gtk.Label('multi line text') label.set_selectable(True) label.set_line_wrap_mode(True) 
+6
source

I usually turn off the beveled frame so that it looks more like a mark, but you can still choose.

GTKEntry without frame .

(There is a rectangle in the picture to the right of the equal sign. It is difficult to see it here, but there is always text in my program, so it is completely clear.)

I do this in Glade, but the GTKEntry.set_has_frame () method.

+2
source

To make it gray, try entry. modify_text() .

0
source

All Articles