开发者

python gtk.window.resize not working when trying to make bigger/smaller window

I have a window that I start in a certain size and want to make smaller or bigger when user does an interaction.. I have made it into a top dock so nothing can maximize over it.

I cannot resize i开发者_JAVA技巧t to a smaller or bigger size, nothing happens.

Here is the code for me creating the window:

window = gtk.Window(gtk.WINDOW_TOPLEVEL)

box = gtk.VBox(homogeneous=False, spacing=0)
window.add(box)
box.pack_start(browser, expand=True, fill=True, padding=0)
window.set_default_size(gtk.gdk.screen_width(),500)
window.move(0, 0)
window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DOCK)
window.show_all()
window.window.property_change("_NET_WM_STRUT", "CARDINAL", 32,
        gtk.gdk.PROP_MODE_REPLACE, [0, 0, 100, 0])

And here is the code i fire when user interacts:

window.resize(gtk.gdk.screen_width(),100)

It does not fire any error codes, but nothing happens..

Anyone know what I am doing wrong?


Your code would work, just need to change this line:

window.resize(gtk.gdk.screen_width(),100) # Instead of gtk.gdk.screen.width()

and It would be better to use below line of code i.e.

window.window.property_change("_NET_WM_STRUT", "CARDINAL", 32,
    gtk.gdk.PROP_MODE_REPLACE, [0, 0, 100, 0])

after the

window.show_all() command

otherwise it will raise error for "NoneType" object.

Your code with some modification:

import gtk

class ResizeWindow:

 def __init__(self):
    self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
    button = gtk.Button("Resize")
    self.window.add(button)
    button.connect("clicked", self.resizewin)
    self.window.set_default_size(gtk.gdk.screen_width(),500)
    self.window.move(0, 0)
    self.window.show_all()
    self.window.window.property_change("_NET_WM_STRUT", "CARDINAL", 32,
           gtk.gdk.PROP_MODE_REPLACE, [0, 0, 100, 0])

 def resizewin(self, widget, *args):
    self.window.resize(gtk.gdk.screen_width(),100)

if __name__ == '__main__':
  ResizeWindow()
  gtk.main()

Hope, it's the same which you want to do.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜