[英]How to set the text size of Gtk.Entry in PyGObject?
I want increase the text size of Gtk.Entry.我想增加 Gtk.Entry 的文本大小。
entry = Gtk.Entry()
I am using Python3我正在使用 Python3
You can use Gtk.Entry.modify_font()
to increase the size of the font. 您可以使用
Gtk.Entry.modify_font()
来增加字体的大小。
Here is an MCVE: 这是一个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.这是针对 Gtk3 的。 They implemented a whole CSS styling engine for theming widgets.
他们为主题小部件实现了一个完整的 CSS 样式引擎。 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在您的主文件中创建一个 CSS Provider 并为您的小部件命名
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现在创建 gtk.css 文件并使用选择器设置命名条目的样式
#unique_entry {
font-family: "Some Cool Font";
font-size: 32px;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.