为什么重绘按钮失败?首先它在我有按钮的地方启动,然后我想在较低的高度调整顶部窗口的大小,然后将按钮也缩小到另一个大小,但是从方法 buttononTop() 重绘按钮失败。
#!/usr/bin/python
import pygtk, gtk, gobject
class GTK_Main:
def __init__(self):
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.set_default_size(800, 768)
self.window.connect("destroy", gtk.main_quit, "WM destroy")
self.vbox = gtk.VBox()
self.window.add(self.vbox)
self.hbox = gtk.HBox(False, 0)
self.vbox.pack_start(self.hbox, False)
self.hbox.set_border_width(10)
self.hbox.pack_start(gtk.Label(), True, True, 0)
self.button2 = gtk.Button("Quit")
self.button2.connect("clicked", self.exit)
self.hbox.pack_start(self.button2, False)
self.button3 = gtk.Button("Test")
self.button3.connect("clicked", self.buttononTop)
self.hbox.pack_start(self.button3, False)
self.hbox.add(gtk.Label())
self.window.show_all()
def buttononTop(self, w):
print "Buttons on top - redraw with different shapes includeing the window"
self.window.remove(self.vbox)
self.window.resize(800, 330)
self.window.set_size_request(800, 330)
# ------------------------------------------- [FAILS STARTS]
self.vbox = gtk.VBox()
self.window.add(self.vbox)
self.hbox = gtk.HBox(False, 0)
self.vbox.pack_start(self.hbox, False)
self.hbox.set_border_width(10)
self.hbox.pack_start(gtk.Label(), True, True, 0)
self.button2 = gtk.Button("Quit")
self.button2.connect("clicked", self.exit)
self.hbox.pack_start(self.button2, False)
self.button3 = gtk.Button("Test")
self.button3.connect("clicked", self.buttononTop)
self.hbox.pack_start(self.button3, False)
self.hbox.add(gtk.Label())
# ------------------------------------------- [FAILS END]
def exit(self, widget, data=None):
gtk.main_quit()
GTK_Main()
gtk.gdk.threads_init()
gtk.main()