【问题标题】:Manage the cursor position in a GtkEntry管理 GtkEntry 中的光标位置
【发布时间】:2017-12-17 22:06:41
【问题描述】:

Python3-Gtk3 如果我替换内容,则在右侧对齐的 GtkEntry 中,光标位于字符串的左侧。我希望他是对的。 'cursor-position' 属性是只读的。如何管理光标位置? 感谢您的帮助。

【问题讨论】:

  • 你能添加你的代码示例吗?

标签: python-3.x gtk3 gtkentry


【解决方案1】:

这是一个给你的例子。在条目中按“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())

【讨论】:

  • 我没有考虑咨询 GtkEditable 对象的方法。非常感谢您提供解决问题的明确快速答案。
  • @phdb44 很高兴能提供帮助。顺便说一句,欢迎来到 SO,我希望你有一个使用 Python + Gtk 的美妙旅程。
猜你喜欢
  • 2018-02-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-11
相关资源
最近更新 更多