How to make a file
Reader and Printer
WorldTechnologyScience
Hey Python Lovers!
This time around, I will give you an
Amazing & Awesome project “file Reader and Printer”.
This project is Especially for
Intermediate Python programmers.
When you run the code, you have to just
select the file and the work type
After Select and hitting Enter.
You will get the Response.
Your file can speak or can print the
inside.
Requirements to Run the Program!
ร Python (version >=
3.2)
ร Pyttsx3 Module (pip install
pyttsx3)
How does it's work:
There
are some Screenshot with a clear explanation
1.
When you start the
program, you have to click an open file Button.
As figure 1
 |
| Opening App |
2. On
click Open file, a screen
pop-up will open where you will select the
file
As shown in figure 2
ร If no file were
selected, it will not forward
 |
| Select any readable file |
3. Now you will select an option, which you
want to process and run, also you can see the file location which you select in
the pop-up
As shown in figure 3
 |
| Select option |
4. As I have selected the “Print a Copy”
Option for the “my_speaker.py” file. And the output will be
You can also see inside the file, without opening it.
Figure
4
 |
| Read and Listen file |
*** When you start the program, a command prompt were open.
if you close it, your program will be also closed.***
The Codes are making file Reader-Printer.
import pyttsx3 # for Speaking
from tkinter import * # for Frame
from tkinter import ttk # for Option_List
from tkinter import filedialog # for Taking file Location
from tkinter import messagebox # for Taking an Alert
# from tkinter import ttk, filedialog, messagebox # As Inline codes
screen = Tk() # to get display
screen.geometry("150x120") # Screen size
screen['bg'] = '#949398' # Screen display color
screen.title('Print - Speaker') # Screen Title
# global given, form, transable # As Inline codes
global given # Global <variable>, which moves any function
global form
global transable
# given, form, transable = StringVar() # Also can use
given = StringVar() # StringVar which gives Input
form = StringVar()
transable = StringVar()
engine = pyttsx3.init('sapi5') # Speech Application Programming Interface (SAPI)
sound = engine.getProperty('voices') # Voices object spporting by driver
engine.setProperty('voices', sound[0].id) # By changing index to change Voice
def says(play): # funtion with taking argument
engine.say(play) # Speak argument
engine.runAndWait() # Take Rest after speak
def open_files(): # Get file
screen.geometry("500x200") # to get display size
# global files, verify, formats, get_file # As inline codes
global files
global verify
global formats
global get_file
get_file = filedialog.askopenfilename() # Select file location
files = open(get_file, "rt") # open selected file and read
# verify = files.name
formats = form.get() # Selected option into var
selection()
# optional_verify() # after opening action Button (line no. 99)
def translate(): # take action on click run!
gives = files
if formats == "Speak File":
gives = str(gives)
for i in gives:
i = i.strip() # Selected file will in strip
says(i) # Speaking Strip
return reset()
elif formats == 'Print a Copy':
j = gives.read() # File will reading full
def show(): # function to print insert file
display=Tk() # new screen for viewing inside files
display.geometry("320x300") # new screen size
display['bg'] = '#cdb599' # color of the screen
display.title('Printed') # display title
Label(display,text=j,fg='black',font='Arial 12',relief=GROOVE,wraplength=280,bd=0).place(x=20,y=15) # Display words
display.mainloop()
reset()
return show()
else: # if error
messagebox.showerror('Fail','Unable to Load\nTry another File or Option.') # Alert! if Error in file
print("Try other file name, Click on open file")
def selection(): # list function
global located
global option_list
font_design = ("Times New Roman", 12, "bold") # font style in a variable
located = Label(screen,text=files.name,font=font_design) # Show file which use for Print or Speak
located.place(x=25,y=155)
option_list = ttk.Combobox(screen,textvariable=form,
values=["Speak File","Print a Copy"],font=font_design) # Option_List
screen.option_add('*TCombobox*Listbox.font', font_design) # Function to store options in a list
option_list.place(x=250,y=50) # position of list
Button(screen,text="Run",font="Arial 12 bold",width="10",command=translate,bg="gray").place(x=350,y=100) # buttom which takes action to RUN!
open_btn = Button(text='Open file', command=open_files) # Button which take file_location.
open_btn.place(x=50,y=50) # Position of Btn
def reset(): # Reset function, to reset after a use.
screen.geometry("150x150")
located.place(x=-500,y=-500) # Hide Location After a work
option_list.set('')
Label(screen,text="Now! Change your file or Reselect recent file! Otherwise it will not run correctly.",font="Arial 12").place(x=25,y=255) # First screen Alert After Run!
screen.mainloop()
If
you like this content and want more like this:
Please
Share it.
If
you have any doubt or queries:
Telegram: https://t.me/learning_with_pk
Instagram: https://www.instagram.com/piyush__bagh/
Visit my Page:
Website: https://worldoftechnologyscience.blogspot.com/
Discord: https://discord.gg/ywzvjtR94T
Facebook: https://www.facebook.com/piyush.baghel.7583/
Twitter: https://twitter.com/PiyushB11061866
Link In: https://www.linkedin.com/in/piyush-baghel-4127aa220/
If
you want an EXE file of it.
So
Please, Comment on me.
Comments
Post a Comment