Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

pygtk

gtk

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.

like image 804
Dumbfounded DM Avatar asked Feb 24 '23 01:02

Dumbfounded DM


1 Answers

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)
like image 92
saeedgnu Avatar answered Apr 05 '23 21:04

saeedgnu