[Tutor] Configuration File, Tkinter, IntVars--Manufacturing Variables

Kent Johnson kent37 at tds.net
Thu Mar 5 18:13:57 CET 2009

On Thu, Mar 5, 2009 at 11:36 AM, Wayne Watson
<sierra_mtnview at sbcglobal.net> wrote:

> It looks like your sample code code has the right idea, but the hang up with
> the original code is getting entered values back to the main program and
> available globally through it. The trick in your code, I think, is to get
> the data back the user entered, and set the main program's global variables
> (to mimic the original program). I'm stuck with the original concept of the
> main code setting self.hourly_rate to the new value to, say, 15 in the
> Dialog setup that calls the Dialog GUI. That is, when the Dialog returns,
> the code must set self.hourly_rate to 15. I may not like that, but that's
> the way the author designed it. I do not want to rewrite lots of code
> because of it. So instead of the code after the return to the from Dialog
> being hard coded, I need to construct executable statements from the list
> above to do the job.

This is not a big change from the code I wrote. Instead of printing
the values, return a dict mapping names to values:
  return dict((name, widget.get()) for name, widget in self.widgets.items())

Then in the caller, use setattr() to set the attributes on self:
  for name, value in returned_values.items():
    setattr(self, name, value)


More information about the Tutor mailing list