Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think it is possible if you do the following:</p> <ol> <li>Identify and isolate the widget W that you want to see updated when you press the button (if you want to see the whole window updated, then make it whatever you add in the window, not the window itself).</li> <li>Write a function (or class) that creates and returns this widget</li> <li>Put this function or class in a module that you will reload </li> <li>Create your button outside W and connect it to a function that does the following <ul> <li>Remove current W from window</li> <li>Reload the module</li> <li>Create new instance of W</li> <li>Add it to the window</li> </ul></li> </ol> <p>Of course, the critical step here is "reload the module". I guess you have to make sure no code from the module is running and no other module depends on variables defined on this module.</p> <p>EDIT: I had some time, so I made a little prototype. Change the label in widget_module.py and then hit Update</p> <p>gui.py</p> <pre><code># Load in pygtk and gtk import pygtk pygtk.require('2.0') import gtk import widget_module # Define the main window class Whc: def __init__(self): # Window and framework self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.window.connect("destroy", self.destroy) # A Button, with an action # Add it to the geometry # show the button self.button = gtk.Button("Update") self.button.connect("clicked", self.update, None) self.vbox = gtk.VBox() self.vbox.pack_start(self.button) self.widget = widget_module.get_widget() self.vbox.pack_start(self.widget) self.window.add(self.vbox) # Show the window self.window.show_all() # Callback function for use when the button is pressed def update(self, widget, data=None): print "Update" self.vbox.remove(self.widget) reload(widget_module) self.widget = widget_module.get_widget() self.vbox.pack_start(self.widget) self.widget.show() # Destroy method causes appliaction to exit # when main window closed def destroy(self, widget, data=None): gtk.main_quit() # All PyGTK applicatons need a main method - event loop def main(self): gtk.main() if __name__ == "__main__": base = Whc() base.main() </code></pre> <p>widget_module.py</p> <pre><code>import pygtk import gtk def get_widget(): return gtk.Label("hello") </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload