In this video we’ll create a simple Spell Checker app with Kivy and Python!
We’ll use the built in Spelling module in Kivy and the PyEnchant Library for the actual spell checking!
We’ll create an app with a label, a textinput box, and a button. Users can enter a word and click the button and the app will check the word for spelling errors and return suggestions of correct spellings.
Python Code: spell.py
GitHub Code: spell.py
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.properties import ObjectProperty
from kivy.lang import Builder
from kivy.core.spelling import Spelling
# Designate Our .kv design file
Builder.load_file('spell.kv')
class MyLayout(Widget):
def press(self):
# Create instance of Spelling
s = Spelling()
# Select the language
s.select_language('en_US')
# See the language options
#print(s.list_languages())
# Grab the word from the textbox
word = self.ids.word_input.text
options = s.suggest(word)
x = ''
for item in options:
x = f'{x} {item}'
# update our label
self.ids.word_label.text = f'{x}'
# Clear input box
self.ids.word_input.text = ''
class AwesomeApp(App):
def build(self):
return MyLayout()
if __name__ == '__main__':
AwesomeApp().run()
Kivy Design Code: spell.kv
GitHub Code: spell.kv
<MyLayout> BoxLayout: orientation: "vertical" size: root.width, root.height Label: id: word_label text_size: self.size halign: "center" valign: "middle" text: "Enter A Word" font_size:32 TextInput: id: word_input multiline: False size_hint: (1, .5) Button: size_hint: (1, .5) font_size: 32 text: "Submit" on_press: root.press()

Add comment