Blob Blame History Raw
<?xml version="1.0" encoding="utf-8"?>
<page xmlns="http://projectmallard.org/1.0/" xmlns:its="http://www.w3.org/2005/11/its" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:e="http://projectmallard.org/experimental/" type="guide" style="task" id="label.py" xml:lang="ko">
  <info>
    <title type="text">Label (Python)</title>
    <link type="guide" xref="beginner.py#display-widgets"/>
    <link type="seealso" xref="properties.py"/>
    <link type="seealso" xref="strings.py"/>
    <link type="next" xref="properties.py"/>
    <revision version="0.2" date="2012-06-18" status="draft"/>

    <credit type="author copyright">
      <name>Marta Maria Casetti</name>
      <email its:translate="no">mmcasetti@gmail.com</email>
      <years>2012</years>
    </credit>
    <credit type="author">
      <name>Sebastian Pölsterl</name>
      <email its:translate="no">sebp@k-d-w.org</email>
      <years>2012</years>
    </credit>

    <desc>적은 양 또는 중간 분량의 글 내용을 나타내는 위젯입니다</desc>
  
    <mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
      <mal:name>조성호</mal:name>
      <mal:email>shcho@gnome.org</mal:email>
      <mal:years>2017</mal:years>
    </mal:credit>
  </info>

  <title>Label</title>
  <media type="image" mime="image/png" src="media/label.png"/>
  <p>간단한 레이블</p>

  <links type="section"/>

  <section id="code">
  <title>예제 결과를 만드는 코드</title>

  <code mime="text/x-python" style="numbered">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)
</code>

    <p>예제 내용을 가져오는 다른 방법은 다른 클래스의 인스턴스로 레이블을 만들고 <code>do_activate(self)</code> 메서드의 <code>MyWindow</code> 인스턴스에 추가하는 식입니다:</p>
    <note>
      <p>강조한 줄은 앞 부분과 다른 코드를 나타냅니다.</p>
    </note>
      <code mime="text/x-python">
# 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
<e:hi>
class MyLabel(Gtk.Label):
    def __init__(self):
        Gtk.Label.__init__(self)
        self.set_text("Hello GNOME!")
</e:hi>

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
<e:hi>
        label = MyLabel()
</e:hi>
        # and add it to the window
<e:hi>
        win.add(label)
</e:hi>
        # show the window and everything on it
        win.show_all()</code>

  </section>

  <section id="methods">
  <title>Label 위젯에 쓸만한 메서드</title>
  
  <note style="tip">
    <p>GTK+에서 문자열을 다루는 방법을 설명하는 내용은 <link xref="strings.py"/>에 있습니다.</p>
  </note>

  <list>
    <item><p><code>set_line_wrap(True)</code> 함수는 레이블의 텍스트가 위젯의 크기 범위를 넘어가는 경우 줄을 바꿉니다.</p></item>
    <item><p><code>set_justify(Gtk.Justification.LEFT)</code>(또는 <code>Gtk.Justification.RIGHT, Gtk.Justification.CENTER, Gtk.Justification.FILL</code>) 함수는 레이블의 텍스트 줄 정렬 방법을 상대적으로 설정합니다. 한 줄 레이블인 경우 이 메서드의 결과는 눈에 띄지 않습니다.</p></item>
    <item><p>텍스트를 꾸밀 때는 <code>set_markup("text")</code> 함수를 사용할 수 있는데, "text"는 <link href="http://developer.gnome.org/pango/stable/PangoMarkupFormat.html">팡고 마크업 언어</link>로 구성한 텍스트입니다:</p>
      <code mime="text/x-python"><![CDATA[
label.set_markup("Text can be <small>small</small>, <big>big</big>, "
                 "<b>bold</b>, <i>italic</i> and even point to somewhere "
                 "on the <a href=\"http://www.gtk.org\" "
                 "title=\"Click to find out more\">internet</a>.")]]></code>
    </item>
  </list>
  </section>

  <section id="references">
  <title>API 참고서</title>
  <p>이 예제는 다음 참고자료가 필요합니다:</p>
  <list>
    <item><p><link href="http://developer.gnome.org/gtk3/unstable/GtkLabel.html">GtkLabel</link></p></item>
    <item><p><link href="http://developer.gnome.org/gtk3/unstable/GtkWindow.html">GtkWindow</link></p></item>
  </list>
  </section>
</page>