How do I commit changes to a text file on button press?
<p>I've written a small <a href="http://www.reddit.com/r/ubuntuappshowdown/comments/vbo7y/my_app_idea_ushare_gui/" rel="nofollow">app that creates a GUI</a> for setting up uShare. Currently it depends heavily on the 'w' (write) and 'a' (append) functions to generate/edit ushare.conf file. But I've been trying to find a way for the app to store all the changes until a save button is pressed, and only then committing them to the actual file. I think that would be the best way of getting around having the user press enter every time they change any field (and indeed allow for GtkCheckButton).</p>

<p>The code giving me errors, (and any code where I use StringIO has the same result:</p>

<pre><code> def on_userinput_activate(self, widget):
    usrinpt = widget.get_text()
    global output
    output = StringIO.StringIO()
    output.write(usrinpt)


def on_savetofile_clicked(self, widget):
    global output
    output = StringIO.StringIO()
    global inserttofile
    inserttofile = output.getvalue()
    logfile = open('/home/boywithaxe/Desktop/test.txt', 'w')
    logfile.write(inserttofile)
</code></pre>
