Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
48 views

Auto Corrector Code in Python

This document discusses code for setting up a GUI in Python using Tkinter to create a spell checker application. It imports necessary libraries like Tkinter, TextBlob, matplotlib and os. It creates functions for clearing text entry boxes and getting a corrected word. It then sets up the GUI window, adds labels and text entry boxes, and buttons to call the correction and clear functions.

Uploaded by

Ali Mola
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views

Auto Corrector Code in Python

This document discusses code for setting up a GUI in Python using Tkinter to create a spell checker application. It imports necessary libraries like Tkinter, TextBlob, matplotlib and os. It creates functions for clearing text entry boxes and getting a corrected word. It then sets up the GUI window, adds labels and text entry boxes, and buttons to call the correction and clear functions.

Uploaded by

Ali Mola
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

import tkinter

win=tkinter.Tk() #creating the main window and storing the window object in 'win'
#We create the widgets here
win.mainloop()
----------------------------------------------------

import matplotlib
matplotlib.use('Agg')

----------------------------------------------------

import os
import matplotlib as mpl
if os.environ.get('DISPLAY','') == '':
print('no display found. Using non-interactive Agg backend')
mpl.use('Agg')
import matplotlib.pyplot as plt

-----------------------------------------------------

### CREATE VIRTUAL DISPLAY ###


!apt-get install -y xvfb # Install X Virtual Frame Buffer
import os
os.system('Xvfb :1 -screen 0 1600x1200x16 &') # create virtual display with
size 1600x1200 and 16 bit color. Color can be changed to 24 or 8
os.environ['DISPLAY']=':1.0' # tell X clients to use our virtual DISPLAY :1.0.

-------------------------------------------------------
%matplotlib inline

--------------------------------------------------------

!apt install ghostscript python3-tk

--------------------------------------------------------

from tkinter import *


from textblob import TextBlob

# Function to clear both the text entry boxes

def clearAll():

# whole content of text entry area is deleted


word1_field.delete(0, END)
word2_field.delete(0, END)

# Function to get a corrected word

def correction():

# get a content from entry box


input_word = word1_field.get()

# create a TextBlob object


blob_obj = TextBlob(input_word)

# get a corrected word


corrected_word = str(blob_obj.correct())

# insert method inserting the


# value in the text entry box.
word2_field.insert(10, corrected_word)

# Driver code
if __name__ == "__main__":

# Create a GUI window


root = Tk()

# Set the background colour of GUI window


root.configure(background='light green')

# Set the configuration of GUI window (WidthxHeight)


root.geometry("400x150")

# set the name of tkinter GUI window


root.title("Spell Corrector")

# Create Welcome to Spell Corrector Application: label


headlabel = Label(root, text='Welcome to Spell Corrector Application',
fg='black', bg="red")

# Create a "Input Word": label


label1 = Label(root, text="Input Word",
fg='black', bg='dark green')

# Create a "Corrected Word": label


label2 = Label(root, text="Corrected Word",
fg='black', bg='dark green')

# grid method is used for placing


# the widgets at respective positions
# in table like structure .
# padx keyword argument used to set padding along x-axis .
headlabel.grid(row=0, column=1)
label1.grid(row=1, column=0)
label2.grid(row=3, column=0, padx=10)

# Create a text entry box


# for filling or typing the information.
word1_field = Entry()
word2_field = Entry()

# padx keyword argument used to set padding along x-axis .


# pady keyword argument used to set padding along y-axis .
word1_field.grid(row=1, column=1, padx=10, pady=10)
word2_field.grid(row=3, column=1, padx=10, pady=10)

# Create a Correction Button and attached


# with correction function
button1 = Button(root, text="Correction", bg="red", fg="black",
command=correction)
button1.grid(row=2, column=1)

# Create a Clear Button and attached


# with clearAll function
button2 = Button(root, text="Clear", bg="red",
fg="black", command=clearAll)

button2.grid(row=4, column=1)

# Start the GUI


root.mainloop()

You might also like