How to set the text size of Gtk.Entry in PyGObject?
Question:
I want increase the text size of Gtk.Entry .
entry = Gtk.Entry()
I am using Python3
Answers:
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()
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;
}
I want increase the text size of Gtk.Entry .
entry = Gtk.Entry()
I am using Python3
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()
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;
}