Dumbfounded DM
Dumbfounded DM

Reputation: 156

How do I make a proper read-only PyGTK text entry?

I'm trying to make a widget that holds a short text output that the user should be able to copy, but not change. This is what I've come up with:

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

It works, but the entry still looks like it's editable, and that looks bad from the user perspective. I tried entry.set_sensitive(False) instead, but this both prevents copying, and makes it look completely disabled.

I would like to know how to make a proper read-only text entry, that's grayed out but still active.

Edit: Here's an image of what I'm talking about, although not GTK (and I'm working in a GNOME environment).

Edit 2: It's starting to look like there's no right way to do this with GTK, if someone can confirm this I'll mark the question solved.

Upvotes: 5

Views: 4715

Answers (3)

saeedgnu
saeedgnu

Reputation: 4376

You can use a Label that is selectable and in wrap 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)

Upvotes: 7

ptomato
ptomato

Reputation: 57940

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

Upvotes: 0

detly
detly

Reputation: 30362

I usually turn off the bevelled frame, so that it looks more like a label but is still selectable.

GTKEntry without frame.

(In the picture, there's a box on the right of the equals sign. It's hard to see here, but in my program there's always text in it, so it's quite clear.)

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

Upvotes: 2

Related Questions