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.
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)
I usually turn off the bevelled frame, so that it looks more like a label but is still selectable.
.(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().
To make it gray, try entry.
modify_text()
.
精彩评论