开发者

PyGTK: Is there a method to calculate the best size for a window?

Most of my GUI programming was done in Java, where you could use a .pack() method that would set the preferred size the window should ha开发者_C百科ve. I'm learning PyGTK now and wondering if such a thing exists in it.


You don't need a pack method. if you don't set a size, the window will adjust to its minimum size. You can use window.set_size_request(-1,-1) to unset any previous size.


Unfortunately... not that I know of. I use the following trick that uses a variety of GTK and GDK methods to work out the screen size of the current monitor at app startup and resizes the root window to have a certain proportion of fill.

Note that root is a GtkWindow. You could, of course, have two values for SCREEN_FILL for horizontal and vertical fill.

SCREEN_FILL = 0.7

class MainApp(object):

    def set_initial_size(self):        
        screen = self.root.get_screen()
        monitor = screen.get_monitor_at_window(self.root.get_window())
        geom = screen.get_monitor_geometry(monitor)
        self.root.set_resize_mode(gtk.RESIZE_QUEUE)
        self.root.resize(
                         int(geom.width * SCREEN_FILL),
                         int(geom.height * SCREEN_FILL))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜