[Tutor] A little help with TKinter please ....!!

Gregor Lingl glingl@aon.at
Tue, 20 Aug 2002 23:00:00 +0200


Graeme Andrew schrieb:

>Hi there ...
>
>I am new to TKinter but have managed to write a  basic user interface, I
>however am puzzled as to how to get data out of the class ?   See following
>code.  Sorry if this is obvious but I am pretty new to this .....
>
>My interface routine is wrapped up in a class and is started with a main
>loop call ...  ie
>
>class Install(Frame):
>   def __init__(self,parent,myFileName):
>     Frame.__init__(self,parent)
>     self.pack()
>     self.data = 0
>     self.make_widgets(self.filecontents)
>
>    .... more methods and code here
>
>Install(None,"textfile").mainloop()
>
>My question is how do I get self.data out of the class and back to the code
>after the 'mainloop' call  ?
>  
>
Although I'm in no way a Tkinter-specialist, I'll try to give some 
remarks to your question,
were it only to help this thread evolve a little more vividly ...

I suppose, if you write "after the mainloop-call", you mean the time 
after this call. (Because code
which is written after this call (in the program) will not be executed - 
The mainloop call causes the
program to wait for events and to execute callback-function-calls which 
are (previously) bound
to some widget.

Now,  if you define in your class a method


     def callback(self,event):
         <Code which has access to all attributes of self
          via the parameter self>

and then bind it (e. g. in the make_widgets-method )
to some widget, like this:

widget.bind("<Button-1>", self.callback)

or

self.bind("<Button-1>", self.callback)

it will be executed whenever this event
(in this case: left mouse button pressed) occurs.

Is it this what you wanted to know? If it helps,
please let me know, and if it was useless also ...

Gregor

You may find some useful links at
http://starship.python.net/lib.html
and at:
http://www.pythonware.com/library/index.htm
See especially: 
 http://www.pythonware.com/library/tkinter/introduction/events-and-bindings.htm


>Many thanks for any help !!
>
>Cheers
>Graeme Andrew
>New Zealand
>
>
>
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor
>
>
>  
>