pygtk entry.set_placeholder_text不起作用 - 缺少tex
我正在附上一块代码,其中我尝试用预定义的文本在入口字段中显示文本。我为此使用entry_placeholder_text,但不幸的是文本未显示。 有有效的解决方案吗?
# -*- coding: utf-8 -*-
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
class MyWindow(Gtk.Window):
def __init__(self):
super(MyWindow, self).__init__()
entry = Gtk.Entry()
entry.set_placeholder_text("Any text")
self.add(entry)
win = MyWindow()
win.connect("destroy", Gtk.main_quit)
win.show_all()
Gtk.main()
I am attaching a piece of my code in which I try to display the text in the Entry field with predefined text. I use entry.set_placeholder_text for this, but unfortunately the text does not appear.
Is there an effective solution?
# -*- coding: utf-8 -*-
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
class MyWindow(Gtk.Window):
def __init__(self):
super(MyWindow, self).__init__()
entry = Gtk.Entry()
entry.set_placeholder_text("Any text")
self.add(entry)
win = MyWindow()
win.connect("destroy", Gtk.main_quit)
win.show_all()
Gtk.main()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
仅当条目为空且未聚焦时,占位符文本才可见。添加另一个可以获得焦点的小部件将使文本出现。
例子:
The placeholder text is only visible when the entry is empty and unfocused. Adding another widget that can get the focus will make the text appear.
Example:
我知道,我不知道为什么它不起作用。
我通常这样做:
在小部件上调用 set_active 之前
I know, I have no idea why it doesn't work.
I usually do:
before calling set_active on the widget