python - Python 中不可扩展的 Gtk+3 侧边栏,用于类似 TreeView 的界面

标签 python gtk

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

我用来制作 TextView (“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)

最佳答案

你可以尝试:

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

关于python - Python 中不可扩展的 Gtk+3 侧边栏,用于类似 TreeView 的界面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42558781/

相关文章:

python scipy.stats.powerlaw 负指数

c - 在 C 中使用 GTK 构建 GUI,使用基本的 Widgets 一切皆有可能吗?或者我应该建立一个自定义的?

python - 用 Popen 模仿 glib.spawn 异步...

gtk - 如何使用glade创建选项卡式 Pane GUI

image - 如何使用 PyGI 在 Python3 中自动调整图像大小?

python - 导入错误 : cannot import name celery

python - 理解ZMQ的HWM

python - 处理相机旋转的正确方法

python - 用 Pandas 按日期范围分组

linux - 由 init 脚本启动的程序中的 GTK+ 对话框