Форум сайта python.su
На этом примере все понятно понятно:
from gi.repository import Gtk class ButtonWindow(Gtk.Window): def __init__(self): Gtk.Window.__init__(self, title="Button Demo") self.set_border_width(10) self.hbox = Gtk.Grid() self.hbox.set_reallocate_redraws(True) self.add(self.hbox) self.button = Gtk.Button("Click Me") self.button.connect("clicked", self.on_click_me_clicked) self.hbox.attach(self.button, 1, 1, 1, 1) button2 = Gtk.Button(stock=Gtk.STOCK_OPEN) button2.connect("clicked", self.on_open_clicked) self.hbox.attach(button2, 1, 2, 1, 1) button3 = Gtk.Button("_Close", use_underline=True) button3.connect("clicked", self.on_close_clicked) self.hbox.attach(button3, 1, 3, 1, 1) def on_click_me_clicked(self, button): self.button.destroy() def on_open_clicked(self, button): self.button = Gtk.Button("Click Me") self.button.connect("clicked", self.on_click_me_clicked) self.hbox.attach(self.button, 1, 1, 1, 1) self.show_all() def on_close_clicked(self, button): print("Closing application") Gtk.main_quit() win = ButtonWindow() win.connect("delete-event", Gtk.main_quit) win.show_all() Gtk.main()
Офлайн
Вот на тако простом примере все перерисовывается:
from gi.repository import Gtk class ButtonWindow(Gtk.Window): def __init__(self): Gtk.Window.__init__(self, title="Button Demo") self.set_border_width(10) self.hbox = Gtk.Grid() self.hbox.set_reallocate_redraws(True) self.add(self.hbox) self.button = Gtk.Button("Click Me") self.button.connect("clicked", self.on_click_me_clicked) self.hbox.attach(self.button, 1, 1, 1, 1) button2 = Gtk.Button(stock=Gtk.STOCK_OPEN) button2.connect("clicked", self.on_open_clicked) self.hbox.attach(button2, 1, 2, 1, 1) button3 = Gtk.Button("Modal window", use_underline=True) button3.connect("clicked", self.mod_win) self.hbox.attach(button3, 1, 3, 1, 1) def mod_win(self, widget): def w_d(*args): win.destroy() def del_but(*args): print(args) self.button.destroy() self.label = Gtk.Label('New') self.hbox.attach(self.label, 1, 1, 1, 1) self.show_all() win = Gtk.Window(default_height=50, default_width=300) win.set_modal(True) win.set_transient_for(self) win.connect("delete-event", w_d) button = Gtk.Button('Delet') button.connect("clicked", del_but) box = Gtk.Box.new(Gtk.Orientation.VERTICAL, 5) box.pack_start(button, True, True, 0) win.add(box) win.show_all() def on_click_me_clicked(self, button): self.button.destroy() def on_open_clicked(self, button): self.button = Gtk.Button("Click Me") self.button.connect("clicked", self.on_click_me_clicked) self.hbox.attach(self.button, 1, 1, 1, 1) self.show_all() def on_close_clicked(self, button): print("Closing application") Gtk.main_quit() win = ButtonWindow() win.connect("delete-event", Gtk.main_quit) win.show_all() Gtk.main()
Отредактировано ivsatel (Март 4, 2015 20:16:39)
Офлайн