468,104 Members | 1,306 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,104 developers. It's quick & easy.

tkinter entry/text widget

I have used the 'entry' tk widget to get text values, I am now using
'Text' but I cant seem to use 'get' method. The TK docs say use
get(index1, index2), I tried numbers and get an error
print self.textMain.get(1,255)

ceback (most recent call last):
ile "C:\Python23\lib\lib-tk\Tkinter.py", line 1345, in __call
return self.func(*args)
ile "blog.py", line 60, in saveFile
print self.textMain.get("1","255")
ile "C:\Python23\lib\lib-tk\Tkinter.py", line 2868, in get
return self.tk.call(self._w, 'get', index1, index2)
Error: bad text index "1"
Jul 18 '05 #1
3 7691
Tk Text widgets do not support indexes in the form of single integers,
since their internal representation is NOT a contiguous block of memory
(which would be horribly inefficient for insertions at the top of a
large document). Instead, you must use indexes of the form
"line.column", where line starts at 1, and column starts at 0. To get
the entire text, you'd use: .get("1.0", END) . Other allowed forms of
indexes are given in the documentation.
Jason Harper
Jul 18 '05 #2
bigbinc wrote:
I have used the 'entry' tk widget to get text values, I am now using
'Text' but I cant seem to use 'get' method. The TK docs say use
get(index1, index2), I tried numbers and get an error
print self.textMain.get(1,255)

ceback (most recent call last):
ile "C:\Python23\lib\lib-tk\Tkinter.py", line 1345, in __call
return self.func(*args)
ile "blog.py", line 60, in saveFile
print self.textMain.get("1","255")
ile "C:\Python23\lib\lib-tk\Tkinter.py", line 2868, in get
return self.tk.call(self._w, 'get', index1, index2)
Error: bad text index "1"


You should go get the Tk command reference OK it's not written in
'Python' but it's still easy to translate.
Download a HTML version from here:--

http://www.tcl.tk/man/

The Exact reference for this problem would be :-

http://www.tcl.tk/man/tcl8.4/TkCmd/text.htm#M18

'Text widget INDICES'

It boils down to passing strings to the .get() method like so:-

myTextWidget.get("0.0", "end")

will get all the text in the Text widget.
HTH
Martin


Jul 18 '05 #3
bigbinc wrote:
I have used the 'entry' tk widget to get text values, I am now using
'Text' but I cant seem to use 'get' method. The TK docs say use
get(index1, index2), I tried numbers and get an error
print self.textMain.get(1,255)

ceback (most recent call last):
ile "C:\Python23\lib\lib-tk\Tkinter.py", line 1345, in __call
return self.func(*args)
ile "blog.py", line 60, in saveFile
print self.textMain.get("1","255")
ile "C:\Python23\lib\lib-tk\Tkinter.py", line 2868, in get
return self.tk.call(self._w, 'get', index1, index2)
Error: bad text index "1"


I was asking for it, I need a couple more months with the language before I
ask the silly newbie questions. I asked anyway.

--
Berlin Brown
bi*****@hotmail.com
Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Mickel Grönroos | last post: by
3 posts views Thread by Phil Schmidt | last post: by
6 posts views Thread by Elaine Jackson | last post: by
7 posts views Thread by William Gill | last post: by
3 posts views Thread by Matt Hammond | last post: by
8 posts views Thread by Dustan | last post: by
8 posts views Thread by Lie | last post: by
reply views Thread by John McMoangle | last post: by
reply views Thread by Leonhard Vogt | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.