FontChooserWidget (Python) Marta Maria Casetti mmcasetti@gmail.com 2012 글꼴을 선택하는 위젯 조성호 shcho@gnome.org 2017 FontChooserWidget

콜백 함수와 사용하는 FontChooserWidget입니다.

예제 결과를 만드는 코드 from gi.repository import Gtk import sys class MyWindow(Gtk.ApplicationWindow): def __init__(self, app): Gtk.Window.__init__(self, title="FontChooserWidget", application=app) # a font chooser self.font_chooser = Gtk.FontChooserWidget() # a default font self.font_chooser.set_font("Sans") # a text to preview the font self.font_chooser.set_preview_text( "This is an example of preview text!") # connect signal from the font chooser to the callback function self.font_chooser.connect("notify::font", self.font_cb) # add the font chooser to the window self.add(self.font_chooser) # callback function: def font_cb(self, event, user_data): # print in the terminal print("You chose the font " + self.font_chooser.get_font()) class MyApplication(Gtk.Application): def __init__(self): Gtk.Application.__init__(self) def do_activate(self): win = MyWindow(self) win.show_all() def do_startup(self): Gtk.Application.do_startup(self) app = MyApplication() exit_status = app.run(sys.argv) sys.exit(exit_status)
FontChooserWidget에 쓸만한 메서드

16번째 줄에서, widget.connect(signal, callback function) 코드로 "notify::font" 시그널을 font_cb() 콜백 함수에 연결했습니다. 더 자세한 설명은 를 참조하십시오.

초기에 선택하는 글꼴을 설정하려면 set_font(font) (font 는 글꼴 이름) 또는 set_font_desc(font) (font 는 PangoFontDescription 객체) 함수를 사용하십시오.

선택한 글꼴을 가져오려면 get_font() 또는 get_font_desc() 함수를 사용하십시오.

미리 보기 화면에 나타난 텍스트를 바꾸려면 set_preview_text() 함수를 사용하십시오.

API 참고서

이 예제는 다음 참고자료가 필요합니다:

GtkFontChooserWidget