[Tutor] Text.index()

Alan Gauld alan.gauld at btinternet.com
Tue Jun 2 16:55:43 CEST 2009


"prasad rao" <prasadaraon50 at gmail.com> wrote

> I created a gui app.I am finding it impossible to
> use Text.insert().please some one give an example of using it.

Look in my tutorial at event driven programming and the Case study. Both 
use the Text widget.


For more detailed info try this introduction:

http://www.linuxjournal.com/article/7357

Or for more detailed info:

http://www.pythonware.com/library/tkinter/introduction/x7883-concepts.htm

>      text.insert(len(myfiles(value1,value2)),myfiles(value1,value2))

I'm not sure what you expected this to do but it looks like you are trying 
to locate
the cursor at the positionn defined by the lengths of your myfiles? But 
then you
don't actually provide any data to insert!

Did you read the Tkinter tutorial on the Text widget?


>    self.tk.call((self._w, 'insert', index, chars) + args)
> TclError: bad text index "178"
>
>  File "C:\Python26\example4.py", line 37, in fshow
>    text.insert(None,myfiles(x))
>  File "C:\Python26\lib\lib-tk\Tkinter.py", line 3001, in insert
>    self.tk.call((self._w, 'insert', index, chars) + args)
> TclError: wrong # args: should be ".18428952.18430232 insert index chars
> ?tagList chars tagList ...?"
> I cant understand what these error messages are telling.

They are both telling you that you are passing the wrong information to 
Text.
It expects an index (in the form of a decimal as dwescribed in the links 
above)
and some text, plus optionally some flags.

Please read the documentation then ask some specific questions
about what you don't understand. The Text widget is immensley powerful
so you need to spend some time studying it to get the best out of it.


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/ 




More information about the Tutor mailing list