如何制作正确的只读PyGTK文本条目?

时间:2022-09-11 17:44:56

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.

它可以工作,但条目看起来仍然是可编辑的,从用户的角度来看这看起来很糟糕。我尝试使用entry.set_sensitive(False),但这都会阻止复制,并使其看起来完全禁用。

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).

编辑:这是我正在谈论的图像,虽然不是GTK(我在GNOME环境中工作)。

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.

编辑2:开始看起来似乎没有正确的方法来使用GTK,如果有人可以确认这一点,我会标记问题已解决。

3 个解决方案

#1


6  

You can use a Label that is selectable and in wrap mode (if the text was more than one line)

您可以使用可选择且处于包装模式的Label(如果文本不止一行)

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

#2


2  

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

我通常会关闭斜面框架,使其看起来更像标签,但仍然可以选择。

如何制作正确的只读PyGTK文本条目?.

(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().

我在Glade中这样做,但方法是GTKEntry.set_has_frame()。

#3


0  

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

要使其变灰,请尝试entry.modify_text()。

#1


6  

You can use a Label that is selectable and in wrap mode (if the text was more than one line)

您可以使用可选择且处于包装模式的Label(如果文本不止一行)

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

#2


2  

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

我通常会关闭斜面框架,使其看起来更像标签,但仍然可以选择。

如何制作正确的只读PyGTK文本条目?.

(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().

我在Glade中这样做,但方法是GTKEntry.set_has_frame()。

#3


0  

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

要使其变灰,请尝试entry.modify_text()。