我是靠谱客的博主 霸气过客,最近开发中收集的这篇文章主要介绍python gtk页面布局,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()

All good when I run it

298a5573c147d540b5220d15c286166f.png

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

Any pointers how to make the grid resize?

0e292fd627b1b30dcabcc56987d1b0fb.png

thanks

解决方案

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()

最后

以上就是霸气过客为你收集整理的python gtk页面布局,gtk python网格调整大小的全部内容,希望文章能够帮你解决python gtk页面布局,gtk python网格调整大小所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(31)

评论列表共有 0 条评论

立即
投稿
返回
顶部