[Tutor] Help with tkinter application.
lonetwin
lonetwin@yahoo.com
Wed, 16 Jan 2002 18:01:01 +0530
Hi all,
read on ..
I work on linux, sometimes on X...My spelling sucks ...and I just *have*
to get the right spelling as I'm editing, I just can't wait till I finish to
run a spell checker on the thingy. So, I keep opening a xtrem window with a
desktop shortcut (Ctrl-W), then type-in "ispell -a", then type in the word
...this works, eez good ...
.... but hey I'm a lazy guy !! an' I haven't tinkered with tkinter much,
so I decide to write TKSpell, a frontend to "ispell -a" and bind it to a
desktop shortcut (BTW---even when I use X, I mostly use the keyboard, I LOVE
WindowMaker that lets me do that). I thought it'd be easy....this is how far
I got.....looks pretty ugly, needs touching/cleaning up, needs suggestions,
that's why it's here, over to you code ...
======================================================================
#!/usr/bin/python
import os
from Tkinter import *
class Spell:
def __init__(self, word):
if not word: return
fin, fout = os.popen2('ispell -a')
version = fout.readline() or "Ispell version unknown"
fin.write(word)
fin.close()
self.result = self.intepret(fout.read())
def intepret(self, output):
if output[0] == '*':
return ('OK',)
if output[0] == '+':
return ('Root', output[2:].strip())
if output[0] == '-':
return ('Compound', output[2:].strip())
if output[0] == '&':
return ('Miss', output[2:].strip())
if output[0] == '?':
return ('Guess', output[2:].strip())
if output[0] == '#':
return ('Not Found',)
def getResult(self):
return self.result
class Tkspell(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.grid(ipadx=4, ipady=4)
self.createWidgets()
def createWidgets(self):
self.entry = Entry(self)
self.entry.grid(column=0, row=0, padx=8)
self.entry.focus()
self.Ok = Button(self, text="Check", activeforeground="blue",
command=self.check)
self.Ok.bind("<Return>", self.check)
self.Ok.grid(column=1, row=0)
def check(self, event):
self.result = Spell(self.entry.get()).getResult()
if self.result[0] in ['OK', 'Root', 'Compound', 'Not Found']:
label = Label(self, text=' '.join([ x for x in self.result]))
label.grid(column=0, row=1, columnspan=2)
self.entry.selection_range(0, END)
return 0
elif self.result[0] in ['Miss', 'Guess']:
suggestions = self.result[1].split(":")[1].split(',')
label = Label(self, text="Suggestions")
label.grid(column=0, row=1, columnspan=2)
ResultList = Listbox(self, height=len(suggestions))
for x in suggestions:
ResultList.insert(END, x)
ResultList.grid(column=0, row=2, columnspan=2, pady=4, sticky=EW)
# print self.result
if __name__ == '__main__':
S = Tkspell()
S.master.title("Tkspell")
S.mainloop()
==============================================
Please help ....if you've got the time to that is....
Peace
Steve
--
----------------------------------------------
I get up each morning, gather my wits.
Pick up the paper, read the obits.
If I'm not there I know I'm not dead.
So I eat a good breakfast and go back to bed.
Oh, how do I know my youth is all spent?
My get-up-and-go has got-up-and-went.
But in spite of it all, I'm able to grin,
And think of the places my get-up has been.
-- Pete Seeger
----------------------------------------------