Reputation: 113
I am using PYGTK to program a very simple download manager, using both wGet and Python. Everything does well but it eats up a lot of screen space... My code:
#!/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()
It throws a lot of unused space at the right. How to fix that? It's very hard to close the application through the 'X' button.
Upvotes: 0
Views: 54
Reputation: 4343
You appear to be creating a table with 2 rows and 6 columns as opposed to the 6 rows and 2 columns I assume you're after - look at the reference documentation and you'll see rows come first in the constructor.
Because you've set homogenous
to True
, the table is setting all columns to the same width and height (that's what homogenous
does), and because you've asked for 6 columns, it's adding a lot of blank ones of the same width which makes your window tremendously wide.
Change the line to:
structure = gtk.Table(6, 2, True)
... and it seems more reasonable. Was that what you were after?
Personally I would suggest creating a HBox
to represent the column. When you need full width widgets, you can just place them directly into this container. If you need a row with multiple widgets, you can create a VBox
to represent the row, add the widgets to that and then add the VBox
itself to the HBox
. This approach may seem slightly fiddlier at first, but it allows GTK to handle more of the layout itself which generally makes your application handle resizing better (as long as you correctly hint whether each widget should be expandable or not). Also, you don't need to go back and change the number of rows and columns if you add more widgets later - VBox
and HBox
are more flexible in that regard. So overall, I've always found these a lot easier unless what I'm after really is a fixed grid of widgets (e.g. if I'm implementing Minesweeper).
Upvotes: 1