Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1082211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:16:04+00:00 2026-05-16T22:16:04+00:00

I am working on a simple messaging system, and need to add the following

  • 0

I am working on a simple messaging system, and need to add the following to a Tkinter text widget:

  1. Spell Check
  2. Option To Change Font ( on selected text )
  3. Option to change font color ( on selected text )
  4. Option to Change Font Size ( on selected text )

I understand that the tkinter Text widget has the ability to use multiple fonts and colors through the tagging mechanism, but I don’t understand how to make use of those capabilities.

How can I implement those features using the features of the Text widget? Specifically, how can I change the font family, color and size of words, and how could I use that to implement something like spellcheck, where misspelled words are underlined or colored differently than the rest of the text.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T22:16:04+00:00Added an answer on May 16, 2026 at 10:16 pm

    The Tkinter text widget is remarkably powerful, but you do have to do some advanced features yourself. It doesn’t have built-in spell check or built-in buttons for bolding text, etc, but they are quite easy to implement. All the capabilities are there in the widget, you just need to know how to do it.

    The following example gives you a button to toggle the bold state of the highlighted text — select a range of characters then click the button to add and then remove the bold attribute. It should be pretty easy for you to extend this example for fonts and colors.

    Spell check is also pretty easy. the following example uses the words in /usr/share/dict/words (which almost certainly doesn’t exist on Windows 7, so you’ll need to supply a suitable list of words) It’s rather simplistic in that it only spell-checks when you press the space key, but that’s only to keep the code size of the example to a minimal level. In the real world you’ll want to be a bit more smart about when you do the spell checking.

    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()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a simple ASP.Net page (handler, actually) where I check the value
I am working on a simple chat application using a System.Windows.Forms.WebBrowser Control to display
I've implemented a messaging system over SQL Server Service Broker. It is working great,
I am working in simple application in which I need to post data to
I'm working on a simple templating system. Basically I'm setting it up such that
I'm looking for good/working/simple to use PHP code for parsing raw email into parts.
I'm working on a simple multiplayer game in which 2-4 players are placed at
i am working on a simple web app which has a user model and
I'm working on a simple 2D game engine in Java, and having no trouble
I'm working on a simple javascript login for a site, and have come up

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.