Label (Python) Marta Maria Casetti mmcasetti@gmail.com 2012 Sebastian Pölsterl sebp@k-d-w.org 2012 적은 양 또는 중간 분량의 글 내용을 나타내는 위젯입니다 조성호 shcho@gnome.org 2017 Label

간단한 레이블

예제 결과를 만드는 코드 from gi.repository import Gtk import sys class MyWindow(Gtk.ApplicationWindow): # constructor for a Gtk.ApplicationWindow def __init__(self, app): Gtk.Window.__init__(self, title="Welcome to GNOME", application=app) self.set_default_size(200, 100) # create a label label = Gtk.Label() # set the text of the label label.set_text("Hello GNOME!") # add the label to the window self.add(label) 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)

예제 내용을 가져오는 다른 방법은 다른 클래스의 인스턴스로 레이블을 만들고 do_activate(self) 메서드의 MyWindow 인스턴스에 추가하는 식입니다:

강조한 줄은 앞 부분과 다른 코드를 나타냅니다.

# a class to define a window class MyWindow(Gtk.ApplicationWindow): def __init__(self, app): Gtk.Window.__init__(self, title="Welcome to GNOME", application=app) self.set_default_size(200, 100) # a class to define a label class MyLabel(Gtk.Label): def __init__(self): Gtk.Label.__init__(self) self.set_text("Hello GNOME!") class MyApplication(Gtk.Application): def __init__(self): Gtk.Application.__init__(self) def do_activate(self): # create an instance of MyWindow win = MyWindow(self) # create an instance of MyLabel label = MyLabel() # and add it to the window win.add(label) # show the window and everything on it win.show_all()
Label 위젯에 쓸만한 메서드

GTK+에서 문자열을 다루는 방법을 설명하는 내용은 에 있습니다.

set_line_wrap(True) 함수는 레이블의 텍스트가 위젯의 크기 범위를 넘어가는 경우 줄을 바꿉니다.

set_justify(Gtk.Justification.LEFT)(또는 Gtk.Justification.RIGHT, Gtk.Justification.CENTER, Gtk.Justification.FILL) 함수는 레이블의 텍스트 줄 정렬 방법을 상대적으로 설정합니다. 한 줄 레이블인 경우 이 메서드의 결과는 눈에 띄지 않습니다.

텍스트를 꾸밀 때는 set_markup("text") 함수를 사용할 수 있는데, "text"는 팡고 마크업 언어로 구성한 텍스트입니다:

small, big, " "bold, italic and even point to somewhere " "on the internet.")]]>
API 참고서

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

GtkLabel

GtkWindow