2

I want increase the text size of Gtk.Entry .

entry = Gtk.Entry()

I am using Python3

Sanjay Prajapat
  • 253
  • 2
  • 13

2 Answers2

5

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

adder
  • 3,512
  • 1
  • 16
  • 28
  • Note that .modify_font() is now deprecated. "gtk_entry_example.py:16: DeprecationWarning: Gtk.Widget.modify_font is deprecated" I have not yet found the replacement. – shevy May 20 '21 at 08:00
1

This is for Gtk3. They implemented a whole CSS styling engine for theming widgets. I won't provide a full program but you'll get the idea from the snippets.

Create a CSS Provider in your main file and give a name to your widget

from gi.repository import Gtk, Gdk    

css_provider = Gtk.CssProvider()
css_provider.load_from_path("/path/to/gtk-3.0/gtk.css")
style_context = Gtk.StyleContext()
style_context.add_provider_for_screen(
    Gdk.Screen.get_default(), css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
)

entry = Gtk.Entry()
entry.set_name("unique_entry")

Now create the gtk.css file and use a selector to style your named entry

#unique_entry {
    font-family: "Some Cool Font";
    font-size: 32px;
}
RiverHeart
  • 549
  • 6
  • 15