PYGTK使用的屏幕空间超出预期

时间:2013-07-01 09:57:23

标签: python pygtk

我正在使用PYGTK编写一个非常简单的下载管理器,同时使用wGet和Python。一切都很好,但它占用了大量的屏幕空间...... 我的代码:

#!/usr/bin/python
import gtk
import os
def submitdownload(self):
    os.system("wget "+site.get_text() + " -P  "+ directory.get_text())
main=gtk.Window()
main.set_title("Simple Downloader with wGet")
structure=gtk.Table(2, 6, True)
label=gtk.Label("Simple downloader with wGet")
sitedes=gtk.Label("Your download link:")
site=gtk.Entry()
submit=gtk.Button("Submit download")
submit.connect("clicked", submitdownload)
directorydes=gtk.Label("Save to: ")
directory=gtk.Entry()
description=gtk.Label("Please don't close the black box (terminal window) or the application will close automatically. It is needed for the download.")
main.add(structure)
structure.attach(label, 0, 2, 0, 1)
structure.attach(sitedes, 0, 1, 1, 2)
structure.attach(site, 1, 2, 1, 2)
structure.attach(submit, 0, 2, 4, 5)
structure.attach(directorydes, 0, 1, 2, 3)
structure.attach(directory, 1, 2, 2, 3)
structure.attach(description, 0, 2, 5, 6)
main.connect("destroy", lambda w: gtk.main_quit())
main.show_all()
gtk.main()

它会在右侧抛出大量未使用的空间。如何解决?通过“X”按钮关闭应用程序非常困难。

1 个答案:

答案 0 :(得分:1)

您似乎正在创建一个包含2行和6列的表,而不是6行和2列我假设您正在使用 - 查看the reference documentation并且您将看到构造函数中的行首先出现

因为您已将homogenous设置为True,所以表格会将所有列设置为相同的宽度和高度(这是homogenous所做的),因为您已经要求6列,它添加了许多相同宽度的空白,使您的窗口非常宽。

将行更改为:

structure = gtk.Table(6, 2, True)

......而且似乎更合理。那就是你追求的吗?

我个人建议创建一个HBox来代表该列。当您需要全宽小部件时,您可以直接将它们放入此容器中。如果您需要包含多个小部件的行,则可以创建VBox来表示该行,将小部件添加到该行,然后将VBox本身添加到HBox。这种方法起初可能看起来略显琐碎,但它允许GTK处理更多的布局本身,这通常会使您的应用程序更好地调整大小(只要您正确地提示每个小部件是否应该是可扩展的)。此外,如果稍后添加更多小部件,则无需返回并更改行数和列数 - VBoxHBox在这方面更灵活。总的来说,我总是发现这些更容易,除非我真正想要的是一个固定的小部件网格(例如,如果我正在实施Minesweeper)。