El widget de texto Tkinter es notablemente potente, pero usted mismo tiene que hacer algunas funciones avanzadas. No tiene un corrector ortográfico incorporado ni botones incorporados para doblar texto, etc., pero son bastante fáciles de implementar. Todas las capacidades están ahí en el widget, solo necesita saber cómo hacerlo.
El siguiente ejemplo muestra un botón para alternar el estado en negrita del texto resaltado: seleccione un rango de caracteres, luego haga clic en el botón para agregar y luego elimine el atributo en negrita. Debería ser bastante fácil para usted extender este ejemplo para fuentes y colores.
El corrector ortográfico es también bastante fácil. el siguiente ejemplo usa las palabras en/usr/share/dict/words (que casi con certeza no existe en Windows 7, por lo que deberá proporcionar una lista adecuada de palabras) Es bastante simplista ya que solo corrector ortográfico cuando presiona la tecla espacio, pero eso es solo para mantener el tamaño del código del ejemplo a un nivel mínimo. En el mundo real, querrás ser un poco más inteligente cuando hagas la revisión ortográfica.
import Tkinter as tk
import tkFont
class App(tk.Tk):
def __init__(self):
tk.Tk.__init__(self)
## Toolbar
self.toolbar = tk.Frame()
self.bold = tk.Button(name="toolbar", text="bold",
borderwidth=1, command=self.OnBold,)
self.bold.pack(in_=self.toolbar, side="left")
## Main part of the GUI
# I'll use a frame to contain the widget and
# scrollbar; it looks a little nicer that way...
text_frame = tk.Frame(borderwidth=1, relief="sunken")
self.text = tk.Text(wrap="word", background="white",
borderwidth=0, highlightthickness=0)
self.vsb = tk.Scrollbar(orient="vertical", borderwidth=1,
command=self.text.yview)
self.text.configure(yscrollcommand=self.vsb.set)
self.vsb.pack(in_=text_frame,side="right", fill="y", expand=False)
self.text.pack(in_=text_frame, side="left", fill="both", expand=True)
self.toolbar.pack(side="top", fill="x")
text_frame.pack(side="bottom", fill="both", expand=True)
# clone the text widget font and use it as a basis for some
# tags
bold_font = tkFont.Font(self.text, self.text.cget("font"))
bold_font.configure(weight="bold")
self.text.tag_configure("bold", font=bold_font)
self.text.tag_configure("misspelled", foreground="red", underline=True)
# set up a binding to do simple spell check. This merely
# checks the previous word when you type a space. For production
# use you'll need to be a bit more intelligent about when
# to do it.
self.text.bind("<space>", self.Spellcheck)
# initialize the spell checking dictionary. YMMV.
self._words=open("/usr/share/dict/words").read().split("\n")
def Spellcheck(self, event):
'''Spellcheck the word preceeding the insertion point'''
index = self.text.search(r'\s', "insert", backwards=True, regexp=True)
if index == "":
index ="1.0"
else:
index = self.text.index("%s+1c" % index)
word = self.text.get(index, "insert")
if word in self._words:
self.text.tag_remove("misspelled", index, "%s+%dc" % (index, len(word)))
else:
self.text.tag_add("misspelled", index, "%s+%dc" % (index, len(word)))
def OnBold(self):
'''Toggle the bold state of the selected text'''
# toggle the bold state based on the first character
# in the selected range. If bold, unbold it. If not
# bold, bold it.
current_tags = self.text.tag_names("sel.first")
if "bold" in current_tags:
# first char is bold, so unbold the range
self.text.tag_remove("bold", "sel.first", "sel.last")
else:
# first char is normal, so bold the whole selection
self.text.tag_add("bold", "sel.first", "sel.last")
if __name__ == "__main__":
app=App()
app.mainloop()
La pregunta ahora no parece pedir un recurso, sino una implementación, como todas las demás preguntas sobre SO también lo hacen. – Trilarion
Estoy perplejo por el cierre debido a estar fuera del tema. Esto no está pidiendo ayudar a encontrar un recurso o herramienta per se, sino cómo implementar algo. Es cierto que es un poco amplio, pero la respuesta aceptada no incluye herramientas externas o bibliotecas, simplemente describe cómo usar las funciones existentes. Creo que esta pregunta merece ser reabierta. –