gtk python网格调整大小 [英] gtk python grid resize

查看:210
本文介绍了gtk python网格调整大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

遵循有关容器的官方教程. 我有下面的代码

Following the official tutorials about containers. I have the follwoing code

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk

class MainWindow(Gtk.Window):

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

        grid = Gtk.Grid()
        self.add(grid)

        button1 = Gtk.Button(label="Button 1")
        button2 = Gtk.Button(label="Button 2")
        button3 = Gtk.Button(label="Button 3")
        button4 = Gtk.Button(label="Button 4")
        button5 = Gtk.Button(label="Button 5")
        button6 = Gtk.Button(label="Button 6")

        grid.add(button1)
        grid.attach(button2, 1, 0, 2, 1)
        grid.attach_next_to(button3, button1, Gtk.PositionType.BOTTOM, 1, 2)
        grid.attach_next_to(button4, button3, Gtk.PositionType.RIGHT, 2, 1)
        grid.attach(button5, 1, 2, 1, 1)
        grid.attach_next_to(button6, button5, Gtk.PositionType.RIGHT, 1, 1)


win = MainWindow()
win.connect("destroy", Gtk.main_quit)
win.show_all()
Gtk.main()

运行时一切正常

但是,如果我调整它的大小,网格将不会随主窗口调整大小.

However if I resize it the grid won't resize with the main window.

任何指针如何使网格调整大小?

Any pointers how to make the grid resize?

谢谢

推荐答案

设置按钮以展开.示例:

Set the buttons to expand. Example:

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk

class MainWindow(Gtk.Window):

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

        grid = Gtk.Grid()
        self.add(grid)

        button1 = Gtk.Button(label="Button 1", expand = True)
        button2 = Gtk.Button(label="Button 2", expand = True)
        button3 = Gtk.Button(label="Button 3", expand = True)
        button4 = Gtk.Button(label="Button 4", expand = True)
        button5 = Gtk.Button(label="Button 5", expand = True)
        button6 = Gtk.Button(label="Button 6", expand = True)

        grid.add(button1)
        grid.attach(button2, 1, 0, 2, 1)
        grid.attach_next_to(button3, button1, Gtk.PositionType.BOTTOM, 1, 2)
        grid.attach_next_to(button4, button3, Gtk.PositionType.RIGHT, 2, 1)
        grid.attach(button5, 1, 2, 1, 1)
        grid.attach_next_to(button6, button5, Gtk.PositionType.RIGHT, 1, 1)


win = MainWindow()
win.connect("destroy", Gtk.main_quit)
win.show_all()
Gtk.main()

这篇关于gtk python网格调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆