python中不可扩展的Gtk + 3边栏,用于类似树视图的界面

时间:2017-03-02 14:58:56

标签: python gtk

我在python中有一个窗口,其中2个盒子容器水平对齐,一个是侧边栏,另一个是文本视图。侧边栏变得比文本视图大,当我调整窗口大小时它会调整大小,仍然超过textview。我该怎么做才能解决这个问题? The program I'm trying to make. Look at the dominant size of the sidebar at left.

我用来制作文本视图(“textview”)和侧边栏(“editview”)的代码。 这是我的代码的一部分!

def __init__(self):
    Gtk.Window.__init__(self, title="Translator")

    self.box = Gtk.Box(spacing=0)
    self.add(self.box)

    self.box_editview = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0, expand=False)
    self.box.pack_start(self.box_editview, True, True, 0)

    vseparator = Gtk.Separator(orientation=Gtk.Orientation.VERTICAL)
    self.box.pack_start(vseparator, False, False, 0)

    self.box_textview = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0)
    self.box.pack_start(self.box_textview, True, True, 0)

    self.css_styling()
    self.create_textview()
    self.create_editview()

def create_editview(self):
    self.palette1 = Gtk.Expander()
    self.palette1.set_spacing(6)
    self.palette1.set_label('Main')
    self.palette1.set_size_request(100,400)

    self.box_editview.pack_start(self.palette1, False, False, 0)

    grid = Gtk.Grid()
    label = Gtk.Label("    font  ")
    button = Gtk.Button.new_with_label("some very cool font")
    grid.add(label)
    grid.add(button)
    self.palette1.add(grid)

def create_textview(self):
    scrolledwindow1 = Gtk.ScrolledWindow()
    scrolledwindow1.set_hexpand(True)
    scrolledwindow1.set_vexpand(True)
    self.box_textview.pack_start(scrolledwindow1, True, True, 0)

    self.textview = Gtk.TextView()
    self.textview.set_wrap_mode(Gtk.WrapMode.WORD)
    self.textbuffer = self.textview.get_buffer()
    self.textbuffer.set_text("text")
    scrolledwindow1.add(self.textview)

1 个答案:

答案 0 :(得分:1)

你可以尝试:

self.box_editview = Gtk.Box( orientation=Gtk.Orientation.VERTICAL, spacing=0, width_request=200 )
self.box.pack_start( self.box_editview, False, False, 0 )