Tkinter text widget dump method ?
Fredrik Lundh
fredrik at effbot.org
Tue Dec 19 14:47:06 EST 2000
Joe Murray wrote:
> In versions Python v 1.5.2 and > and Tkinter v 1.129 and >, there are no
> implementations of the Tkinter.Text widget dump methods.
from the eff-bot archives:
http://www.deja.com/getdoc.xp?AN=405964453
From: "Fredrik Lundh" <fredrik at pythonware.com>
Subject: Re: Tkinter.Text dump not implemented ?
Date: 28 Oct 1998
:::
#
# dump the contents of text widget
#
# fredrik lundh, october 1998
#
# fredrik at pythonware.com
# http://www.pythonware.com
#
from Tkinter import *
import string, random
def dump(text):
dump = text.tk.splitlist(text.tk.call(text, "dump", 1.0, "end"))
data = []
for i in range(0, len(dump), 3):
data.append(tuple(dump[i:i+3]))
return data # a list of (tag, str, pos) tuples
# --------------------------------------------------------------------
# sample code
root = Tk()
text = Text(root, font="courier", width=65, wrap=WORD)
text.pack()
text.insert(END, (9*"-"+"!")*6 + "-----\n")
for i in range(200):
text.insert(END, random.choice(("spam ", "and ", "egg ")))
for tag, str, pos in dump(text):
print pos, tag, "=", repr(str)
root.mainloop()
:::
</F>
<!-- (the eff-bot guide to) the standard python library:
http://www.pythonware.com/people/fredrik/librarybook.htm
-->
More information about the Python-list
mailing list