1

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

4

1 回答 1

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())
于 2017-12-17T14:06:41.003 回答