Manage the cursor position in a GtkEntry

1.4k Views Asked by At

Python3-Gtk3 In a GtkEntry justified on the right if I replace the content the cursor is on the left of the string. I would like him to be right. The 'cursor-position' property is read-only. How to manage the cursor position? Thanks for your help.

1

There are 1 best solutions below

2
On BEST ANSWER

Here is an example for you. Press 'Enter' in the entry to see the results.

#!/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())