Turtle moving circle

import turtle

def moving_object(move):

    move.fillcolor('Purple') 

    move.begin_fill() 

    move.circle(10)  

    move.end_fill()             

if __name__ == "__main__" :

    screen = turtle.Screen() 

    screen.setup(600,600)    

    # screen background color

    screen.bgcolor('white')   

    screen.tracer(0)           

    move = turtle.Turtle() 

    move.color('Purple')

    move.speed(0) 

    move.width(2)     

    move.hideturtle()          

    move.penup()               

    move.goto(-250, 0) 

    move.pendown()             

    while True :

        move.clear()  

        moving_object(move)   

        screen.update()    

        move.forward(0.5)      

creating a real time color detector

#Color Detection

import numpy as np

import cv2

# Capturing video through webcam

webcam = cv2.VideoCapture(0)

while(1):

_, imageFrame = webcam.read()

# Convert the imageFrame in

# BGR(RGB color space) to

# HSV(hue-saturation-value)

# color space

hsvFrame = cv2.cvtColor(imageFrame, cv2.COLOR_BGR2HSV)

red_lower = np.array([136, 87, 111], np.uint8)

red_upper = np.array([180, 255, 255], np.uint8)

red_mask = cv2.inRange(hsvFrame, red_lower, red_upper)

green_lower = np.array([25, 52, 72], np.uint8)

green_upper = np.array([102, 255, 255], np.uint8)

green_mask = cv2.inRange(hsvFrame, green_lower, green_upper)

blue_lower = np.array([94, 80, 2], np.uint8)

blue_upper = np.array([120, 255, 255], np.uint8)

blue_mask = cv2.inRange(hsvFrame, blue_lower, blue_upper)

kernal = np.ones((5, 5), "uint8")

red_mask = cv2.dilate(red_mask, kernal)

res_red = cv2.bitwise_and(imageFrame, imageFrame,

mask = red_mask)

green_mask = cv2.dilate(green_mask, kernal)

res_green = cv2.bitwise_and(imageFrame, imageFrame,

mask = green_mask)

blue_mask = cv2.dilate(blue_mask, kernal)

res_blue = cv2.bitwise_and(imageFrame, imageFrame,

mask = blue_mask)

contours, hierarchy = cv2.findContours(red_mask,

cv2.RETR_TREE,

cv2.CHAIN_APPROX_SIMPLE)

for pic, contour in enumerate(contours):

area = cv2.contourArea(contour)

if(area > 300):

x, y, w, h = cv2.boundingRect(contour)

imageFrame = cv2.rectangle(imageFrame, (x, y),

(x + w, y + h),

(0, 0, 255), 2)

cv2.putText(imageFrame, "Red Colour", (x, y),

cv2.FONT_HERSHEY_SIMPLEX, 1.0,

(0, 0, 255))

contours, hierarchy = cv2.findContours(green_mask,

cv2.RETR_TREE,

cv2.CHAIN_APPROX_SIMPLE)

for pic, contour in enumerate(contours):

area = cv2.contourArea(contour)

if(area > 300):

x, y, w, h = cv2.boundingRect(contour)

imageFrame = cv2.rectangle(imageFrame, (x, y),

(x + w, y + h),

(0, 255, 0), 2)

cv2.putText(imageFrame, "Green Colour", (x, y),

cv2.FONT_HERSHEY_SIMPLEX,

1.0, (0, 255, 0))

contours, hierarchy = cv2.findContours(blue_mask,

cv2.RETR_TREE,

cv2.CHAIN_APPROX_SIMPLE)

for pic, contour in enumerate(contours):

area = cv2.contourArea(contour)

if(area > 300):

x, y, w, h = cv2.boundingRect(contour)

imageFrame = cv2.rectangle(imageFrame, (x, y),

(x + w, y + h),

(255, 0, 0), 2)

cv2.putText(imageFrame, "Blue Colour", (x, y),

cv2.FONT_HERSHEY_SIMPLEX,

1.0, (255, 0, 0))

# Program Termination

cv2.imshow("Multiple Color Detection in Real-TIme", imageFrame)

if cv2.waitKey(1) & 0xFF == ord('q'):

cap.release()

cv2.destroyAllWindows()

break


Screen recorder

# importing packages

import pyautogui

import cv2

import numpy as np

#resolution

resolution = (1920, 1080)

codec = cv2.VideoWriter_fourcc(*"XVID")

#Output file

filename = "Recordings.avi"

#frames rate

fps = 60.0

# Create a VideoWriter object

out = cv2.VideoWriter(filename, codec, fps, resolution)

# Creating an Empty window

cv2.namedWindow("Live", cv2.WINDOW_NORMAL)

# Resize this window

cv2.resizeWindow("Live", 480, 270)

while True:

# Take screenshot using PyAutoGUI

img = pyautogui.screenshot()

# Convert the screenshot to a numpy array

frame = np.array(img)

# Convert it from BGR(Blue, Green, Red) to

# RGB(Red, Green, Blue)

frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)

# Write output file

out.write(frame)

#Display the recording screen

cv2.imshow('Live', frame)

# Stop recording when we press 'q'

if cv2.waitKey(1) == ord('q'):

break

# Release the Video writer

out.release()

# Destroy windows

cv2.destroyAllWindows()


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()