Title: Signature.html
I browsed through your response, and it looks like this may be doable. I'll look this over more carefully this evening. It seems as though someone should have had a similar problem in the past. The Tkinter interface seems to be a, I hope, temporary logjam. I don't recall XWindow widgets needing the control variable notion. 

I've already overhauled a lot of the code, and names, initial values are in list/dictionary form. That all works, but I've just started considering how all this can be carried into the two objects mentioned here.  Note too that I need to take care of things like self.anumberVar = StringVar(). 

I noted the eval too. Not my code. When the dust clears, I'll look at it. The program is not for general distribution.

As an aside, I've finally latched on to the idea of attributes in Python terms.  The idea seems local to Python.

Alan Gauld wrote:
"Wayne Watson" <sierra_mtnv...@sbcglobal.net> wrote

see my post of yesterday, "Maintaining the Same Variable Type--Tkinter",
went over like a lead balloon. :-)

Yeah, I had no idea what you meant :-)

 I've heavily modified the original code to accept a config file,
and set up variable to initialize the widgets, trying to bridge
some code in the Enter_Data_Dialog and Set_Enter_Data
objects control variable code is where the trouble lays

Yep, and part of it is the attempt to create variables dynamically.
It's so much easier if you use a dictionary or a list of name,value
tuples.

The code below puts up a window with one menu and two
submenus items,  Enter Data, and Exit. Select Enter Data
and put in an integer number. It all works fine.

It works with hard coded variable names. Trying to use dynamic
variable names will be much trickier!

Basically, what I want to do is eliminate code like
dialog.anumberVar.get() and replace it by constructing the
appropriate names for the config file.

If you used a list of variables you could replace it with

self.varList[0][1] = dialog.myVar.get()

In this case, the config file might contain:
   anumber = 123

and you store that as
varList.append( (varname, varValue) )

If there is only one variable at a time you could just use the
tuple of course:

self.myVar = (varname, varValue)

Then the dialog return becomes:

self.myVar[1] = dialog.myVar.get()

You also need to make the dialog smart enough to read
the name of the variable (myVar[0]) and set the label
accordingly... If you use dynamic variables you will need
to pass in the variable name and then use getattr to
retrieve the value. Or pass name and value - which
sounds a lot like a tuple?

The problem with trying to create actual variables is that
the rest of yor code must become psychic (or very complex)
to figure out what variable to use. Or you write a lott of
near identical code to handle every possible variable name!

BTW, the Quit function is original but doesn't kill the window
when Quit is used. What fixes that?

Brute force you can use sys.exit()!

But more normally you can use what you have used,
so I'm not sure why its not working!

For more bonus points, it seems as though the try statement
in the dialog should really bring up an "Error" dialog saying
something is wrong, when an invalid entry occurs.

You can use the standard 'showerror' or 'showwarning' dialogs
for that:

http://www.pythonware.com/library/tkinter/introduction/standard-dialogs.htm

Finally I note the use of eval() to evaluate the user input. That is bad,
bad bad. And looks like there is no need since after eval'ing you
then use int(). You should be able to use int() directly on the input
and handle any ValueError exceptions etc to catch bad input.

HTH,



--
           Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

             (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)
            

                In mathematics you don't understand things. 
                 You just get used to them.” -- John Von Neumann
                    (P.S. The same is true in life.)

                    Web Page: <www.speckledwithstars.net/>
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to