Tkinter md5 problem
Dominic
oblivious at web.de
Sat Dec 28 13:42:29 EST 2002
Dagur Páll Ammendrup wrote:
> Hi!
>
> In the Introduction to Tkinter I found this method to detect if the
> contents in a Text widget have changed:
>
> ---------------------------------------------------
> import md5
> def getsignature(contents):
> return md5.md5(contents).digest()
>
> text.insert(END, contents) # original contents
> signature = getsignature(contents)
>
> ...
>
> contents = text.get(1.0, END)
> if signature != getsignature(contents):
> print "contents have changed!"
>
> ---------------------------------------------------
>
> This does work, but only if you're using ASCII, otherwise you get a
> UnicodeError
>
> UnicodeError: ASCII encoding error: ordinal not in range(128)
>
> So what can I do?
> Thanks in advance!
I received that error message when I tried
to write tkinter messagebox user input to a
file. You may want to convert the unicode
strings to ASCII:
x=x.encode('iso-8859-15')
Ciao,
Dominic
P.S. Using cryptographic hash functions to discover gui
interaction is probably the reason for slow python
gui applications ;-), probably they have used this
technique in swing (java) too ;-)))
>
> -Dagur
>
More information about the Python-list
mailing list