我有一个 python 窗口,其中有 2 个水平对齐的盒子容器,一个是侧边栏,另一个应该是 TextView 。侧边栏变得比 TextView 更大,并且当我调整窗口大小时它会调整大小,仍然超过 TextView 。我能做什么来解决这个问题?
我用来制作 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/