【发布时间】:2017-12-17 22:06:41
【问题描述】:
Python3-Gtk3 如果我替换内容,则在右侧对齐的 GtkEntry 中,光标位于字符串的左侧。我希望他是对的。 'cursor-position' 属性是只读的。如何管理光标位置? 感谢您的帮助。
【问题讨论】:
-
你能添加你的代码示例吗?
标签: python-3.x gtk3 gtkentry
Python3-Gtk3 如果我替换内容,则在右侧对齐的 GtkEntry 中,光标位于字符串的左侧。我希望他是对的。 'cursor-position' 属性是只读的。如何管理光标位置? 感谢您的帮助。
【问题讨论】:
标签: python-3.x gtk3 gtkentry
这是一个给你的例子。在条目中按“Enter”以查看结果。
#!/usr/bin/env python
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
import os, sys
class GUI:
def __init__(self):
window = Gtk.Window()
entry = Gtk.Entry()
entry.connect("activate", self.entry_activated )
entry.set_alignment(1.0)
window.add(entry)
window.show_all()
window.connect("destroy", self.on_window_destroy )
def on_window_destroy(self, window):
Gtk.main_quit()
def entry_activated (self, entry):
text = entry.get_text()
text = text * 2
entry.set_text(text)
length = len(text)
entry.set_position(length)
def main():
app = GUI()
Gtk.main()
if __name__ == "__main__":
sys.exit(main())
【讨论】: