Search code examples
pythongtk3pygobject

How to set the text size of Gtk.Entry in PyGObject?


I want increase the text size of Gtk.Entry .

entry = Gtk.Entry()

I am using Python3


Solution

  • You can use Gtk.Entry.modify_font() to increase the size of the font.

    Here is an MCVE:

    import gi
    gi.require_version('Gtk', '3.0')
    from gi.repository import Gtk, Pango
    
    class EntryWindow(Gtk.Window):
    
        def __init__(self):
            super().__init__(title='Entry Widget')
            self.set_size_request(200, 100)
            self.entry = Gtk.Entry()
            self.entry.set_text("Hello World")
            self.entry.set_alignment(xalign=0.5)
            self.entry.modify_font(Pango.FontDescription('Dejavu Sans Mono 20'))
            self.add(self.entry)
    
    win = EntryWindow()
    win.connect("delete-event", Gtk.main_quit)
    win.show_all()
    Gtk.main()
    

    Example