Book Image

Kivy Cookbook

By : Hugo Solis
Book Image

Kivy Cookbook

By: Hugo Solis

Overview of this book

Table of Contents (16 chapters)
Kivy Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Using spelling


Depending on the kind of app that we will develop, we will need to spellcheck text provided by the user. In the Kivy API, there is a package to deal with it. In this recipe, we will give an example of how to do it.

Getting ready

If you are not using Mac OS X (or OS X as Apple called now), we will need to install the Python package: PyEnchant. For the installation, let's use the pip tool as follows:

pip install PyEnchant

How to do it…

Because this recipe could use it in different contexts, let's work directly in Python. We want to make some suggestions to the word misspelled. To complete the task, follow these steps:

  1. Import the Spelling package.

    from kivy.core.spelling import Spelling
    
  2. Instance the object s as Spelling().

    s = Spelling()
    
  3. List the available language.

    s.list_languages()
    
  4. In this case, select U.S. English.

    s.select_language('en_US')
    
  5. Ask for a suggestion to the object s.

    s.suggest('mispell')
    

How it works…

The first four steps actually set the kind of suggestion that we want...