스크롤 창에 이미지를 나타냅니다.
from gi.repository import Gtk
import sys
class MyWindow(Gtk.ApplicationWindow):
def __init__(self, app):
Gtk.Window.__init__(
self, title="ScrolledWindow Example", application=app)
self.set_default_size(200, 200)
# the scrolledwindow
scrolled_window = Gtk.ScrolledWindow()
scrolled_window.set_border_width(10)
# there is always the scrollbar (otherwise: AUTOMATIC - only if needed
# - or NEVER)
scrolled_window.set_policy(
Gtk.PolicyType.ALWAYS, Gtk.PolicyType.ALWAYS)
# an image - slightly larger than the window...
image = Gtk.Image()
image.set_from_file("gnome-image.png")
# add the image to the scrolledwindow
scrolled_window.add_with_viewport(image)
# add the scrolledwindow to the window
self.add(scrolled_window)
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)
set_policy(hscrollbar_policy, vscrollbar_policy)
함수에서 각 인자에는 수평 수직 방향으로 스크롤 표시줄을 나타낼지 여부를 정규화 한 Gtk.Policy.AUTOMATIC, Gtk.Policy.ALWAYS, Gtk.Policy.NEVER
값 중 하나가 들어갑니다. AUTOMATIC
값을 넣으면 필요할 경우 나타내며, ALWAYS
, NEVER
는 값에서 설명하는 의미와 같습니다.
add_with_viewport(widget)
함수는 창에 자체 스크롤 기능을 넣지 않고 Gtk.Widget widget
을 추가하는데 사용합니다.
set_placement(window_placement)
함수는 스크롤 창에서 스크롤 표시줄을 나타낼 컨텐트 위치를 설정합니다. 인자 옵션은 Gtk.CornerType.TOP_LEFT
(기본값: 스크롤 표시줄을 창 하단과 우측에 나타냄), Gtk.CornerType.TOP_RIGHT, Gtk.CornerType.BOTTOM_LEFT, Gtk.CornerType.BOTTOM_RIGHT
가 있습니다.
set_hadjustment(adjustment)
함수와 set_vadjustment(adjustment)
함수는 각각 Gtk.Adjustment adjustment
를 설정합니다. 상한 값, 하한 값, 단계/페이지 증가 값, 페이지 크기를 나타내며, Gtk.Adjustment(value, lower, upper, step_increment, page_increment, page_size)
로 만듭니다. 여기서 각 필드 값은 float
형식입니다. (참고로 지금 같은 경우는 step_increment
를 사용하지 않으므로 0
값으로 설정합니다).
이 예제는 다음 참고자료가 필요합니다:
GtkScrolledWindow
표준 서수형 값 목록
GtkImage