Grid(Python) Tiffany Antopolski tiffany.antopolski@gmail.com 2012 Marta Maria Casetti mmcasetti@gmail.com 2012 위젯을 행열 방향으로 감쌉니다 조성호 shcho@gnome.org 2017 Grid

그리드에 레이블 몇 개를 넣어봤습니다.

예제 결과를 만드는 코드 from gi.repository import Gtk import sys class MyWindow(Gtk.ApplicationWindow): def __init__(self, app): Gtk.Window.__init__(self, title="Grid Example", application=app) # three labels label_top_left = Gtk.Label(label="This is Top Left") label_top_right = Gtk.Label(label="This is Top Right") label_bottom = Gtk.Label(label="This is Bottom") # a grid grid = Gtk.Grid() # some space between the columns of the grid grid.set_column_spacing(20) # in the grid: # attach the first label in the top left corner grid.attach(label_top_left, 0, 0, 1, 1) # attach the second label grid.attach(label_top_right, 1, 0, 1, 1) # attach the third label below the first label grid.attach_next_to( label_bottom, label_top_left, Gtk.PositionType.BOTTOM, 2, 1) # add the grid to the window self.add(grid) class MyApplication(Gtk.Application): def __init__(self): Gtk.Application.__init__(self) def do_activate(self): win = MyWindow(self) win.show_all() app = MyApplication() exit_status = app.run(sys.argv) sys.exit(exit_status)
Grid 위젯에 쓸만한 메서드

width, height 크기로 left, top 위치에 child 위젯을 붙이려면 attach(child, top, left, width, height) 함수를 사용하십시오, sibling 위젯을 이미 두었다면 attach_next_to(child, sibling, side, width, height) 함수를 사용할 수 있습니다. 여기서 side 값은 Gtk.PositionType.LEFT, Gtk.PositionType.RIGHT, Gtk.PositionType.TOP, Gtk.PositionType.BOTTOM 중 하나입니다.

insert_row(position) 함수와 insert_column(position) 함수는 주어진 이름대로 정확하게 동작합니다. 이 위치 옆에 붙은 하위 요소 또는 아래에 붙은 하위 요소를 한줄 아래로 내리며, 이 위치의 하위 요소는 (종,횡 방향으로) 새 줄을 확장합니다. insert_next_to(sibling, side) 함수는 지정 위치에 줄이나 행을 넣습니다. 즉, 이 함수는 새 줄 또는 행을 sibling 다음의 side에서 지정한 위치에 넣습니다. side 값이 Gtk.PositionType.TOP 또는 Gtk.PositionType.BOTTOM이면 새 줄을 넣고, Gtk.PositionType.LEFT 또는 Gtk.PositionType.RIGHT면 새 칸을 넣습니다.

set_row_homogeneous(True) 함수는 각각 모든 줄의 높이를 동일하게 설정하며 set_column_homogeneous(True) 함수는 모든 칸의 너비를 동일하게 설정합니다.

set_row_spacing(spacing)함수는 줄 간격을 강제로 설정하고 set_column_spacing(spacing) 함수는 칸 간격을 강제로 설정합니다. spacing 값은 기본값 0에서 32767값 사이입니다.

API 참고서

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

GtkApplication

GtkApplicationWindow

GtkLabel

GtkImage

GtkGrid