ToDo App

from tkinter import *

from tkinter import messagebox

tasks_list = []

counter = 1

def inputError() :

if enterTaskField.get() == "" :

messagebox.showerror("Input Error")

return 0

return 1

def clear_NumberField() :

taskNumberField.delete(0.0, END)

def clear_taskField() :

enterTaskField.delete(0, END)

# Function for inserting the content

# from the task entry field to the text area

def insertTask():

global counter

value = inputError()

if value == 0 :

return

content = enterTaskField.get() + "\n"

# store task in the list

tasks_list.append(content)

TextArea.insert('end -1 chars', "[ " + str(counter) + " ] " + content)

counter += 1

clear_taskField()


# function for deleting the specified task

def delete() :

global counter

if len(tasks_list) == 0 :

messagebox.showerror("No task")

return

# get the task number, which is required to delete

number = taskNumberField.get(1.0, END)

if number == "\n" :

messagebox.showerror("input error")

return

else :

task_no = int(number)

# function calling for deleting the

# content of task number field

clear_NumberField()

# deleted specified task from the list

tasks_list.pop(task_no - 1)

# decremented

counter -= 1

TextArea.delete(1.0, END)

for i in range(len(tasks_list)) :

TextArea.insert('end -1 chars', "[ " + str(i + 1) + " ] " + tasks_list[i])

if __name__ == "__main__" :

gui = Tk()

gui.configure(background = "light blue")

gui.title("ToDo App")

gui.geometry("250x300")

enterTask = Label(gui, text = "Enter Your Task", bg = "light blue")

enterTaskField = Entry(gui)

Submit = Button(gui, text = "Submit", fg = "Black", bg = "light yellow", command = insertTask)

TextArea = Text(gui, height = 5, width = 25, font = "lucida 13")

taskNumber = Label(gui, text = "Delete Task Number", bg = "Red")

taskNumberField = Text(gui, height = 1, width = 2, font = "lucida 13")

delete = Button(gui, text = "Delete", fg = "Black", bg = "Red", command = delete)

Exit = Button(gui, text = "Exit", fg = "Black", bg = "Red", command = exit)

enterTask.grid(row = 0, column = 2)

enterTaskField.grid(row = 1, column = 2, ipadx = 50)

Submit.grid(row = 2, column = 2)

TextArea.grid(row = 3, column = 2, padx = 10, sticky = W)

taskNumber.grid(row = 4, column = 2, pady = 5)

taskNumberField.grid(row = 5, column = 2)

delete.grid(row = 6, column = 2, pady = 5)

Exit.grid(row = 7, column = 2)

gui.mainloop()


Creating a AudioBook

 Installing pyttsx3:

          pip install pyttsx3

Installing espeak:

          sudo apt install espeak


import pyttsx3
book=open(r"#add_path_of_txt_file")
book_text=book.readlines()
engine = pyttsx3.init()
for i in book_text:
engine.say(i)
engine.runAndWait()

Voice Recorder using python

 install portaudio using:

               pip install portAudio

install portaudio library:
    
               sudo apt-get install libportaudio2


import sounddevice
from scipy.io.wavfile import write 
fs=44100 #sample_rate
second=int(input("Enter the time duration in second: "))
print("Recording....\n")
record_voice=sounddevice.rec(int(second * fs),samplerate=fs,channels=2)
sounddevice.wait()
write("out.wav",fs,record_voice)
print("Finished....\nPlease check it...")

Compound Interest GUI Calculator using Tkinter

# importing classes and functions from the tkinter

from tkinter import *

# Function for clearing the

# contents of all entry boxes

def clear_all() :

# whole content of entry boxes is deleted

principle_field.delete(0, END)

rate_field.delete(0, END)

time_field.delete(0, END)

compound_field.delete(0, END)

# set focus on the principle_field entry box

principle_field.focus_set()

# Function to find compound interest

def calculate_ci():

# get a content from entry box

principle = int(principle_field.get())

rate = float(rate_field.get())

time = int(time_field.get())

# Calculates compound interest

CI = principle * (pow((1 + rate / 100), time))

# insert method inserting the

# value in the text entry box.

compound_field.insert(10, CI)

#code

if __name__ == "__main__" :

# Create a GUI window

root = Tk()

# Set the background colour of GUI window

root.configure(background = 'white')

# Set the configuration of GUI window

root.geometry("400x250")

# set the name of tkinter GUI window

root.title("Compound Interest Calculator")

# Create a Principle Amount : label

label1 = Label(root, text = "Principle Amount(Rs) : ",

fg = 'white', bg = 'black')

# Create a Rate : label

label2 = Label(root, text = "Rate(%) : ",

fg = 'white', bg = 'black')

# Create a Time : label

label3 = Label(root, text = "Time(years) : ",

fg = 'white', bg = 'black')


# Create a Compound Interest : label

label4 = Label(root, text = "Compound Interest : ",

fg = 'white', bg = 'black')

# 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 .

# pady keyword argument used to set padding along y-axis .

label1.grid(row = 1, column = 0, padx = 10, pady = 10)

label2.grid(row = 2, column = 0, padx = 10, pady = 10)

label3.grid(row = 3, column = 0, padx = 10, pady = 10)

label4.grid(row = 5, column = 0, padx = 10, pady = 10)

# Create a entry box

# for filling or typing the information.

principle_field = Entry(root)

rate_field = Entry(root)

time_field = Entry(root)

compound_field = Entry(root)

# 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 .

# pady keyword argument used to set padding along y-axis .

principle_field.grid(row = 1, column = 1, padx = 10, pady = 10)

rate_field.grid(row = 2, column = 1, padx = 10, pady = 10)

time_field.grid(row = 3, column = 1, padx = 10, pady = 10)

compound_field.grid(row = 5, column = 1, padx = 10, pady = 10)

# Create a Submit Button and attached

# to calculate_ci function

button1 = Button(root, text = "Submit", bg = "red",

fg = "black", command = calculate_ci)

# Create a Clear Button and attached

# to clear_all function

button2 = Button(root, text = "Clear", bg = "red",

fg = "black", command = clear_all)

button1.grid(row = 4, column = 1, pady = 10)

button2.grid(row = 6, column = 1, pady = 10)

# Start the GUI

root.mainloop()


Number guessing game (Basic Python Project)

import random

import math

# Taking Inputs

lower_input = int(input("Enter lower_input number:- "))

# Taking Inputs

upper_input = int(input("Enter upper_input number:- "))

# generating random number between

# the lower_input and upper_input

x = random.randint(lower_input, upper_input)

print("\n\tYou've only ",

round(math.log(upper_input - lower_input + 1, 2)),

" chances to guess the integer!\n")

# Initializing the number of guesses.

count = 0

# for calculation of minimum number of

# guesses depends upon range

while count < math.log(upper_input - lower_input + 1, 2):

count += 1

# taking guessing number as input

guess = int(input("Guess a number:- "))

# Condition testing

if x == guess:

print("Congratulations you did it in ",

count, " try")

# Once guessed, loop will break

break

elif x > guess:

print("You guessed too small!")

elif x < guess:

print("You Guessed too high!")

# If Guessing is more than required guesses,

# shows this output.

if count >= math.log(upper_input - lower_input + 1, 2):

print("\nThe number is %d" % x)

print("\tBetter Luck Next time!")