Fire detection

import cv2

import numpy as np

import matplotlib.pyplot as plt

live_camera = cv2.VideoCapture(0)

while(live_camera.isOpened()):

    ret, frame = live_camera.read()

    cv2.imshow("Fire Detection",frame)

    if cv2.waitKey(10) == 27:

        break

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

img_cap = plt.imshow(img_RGB)

plt.show()

live_camera.release()

cv2.destroyAllWindows()


Notepad

import tkinter

import os

from tkinter import *

from tkinter.messagebox import *

from tkinter.filedialog import *

class Notepad:

__root = Tk()

__thisWidth = 300

__thisHeight = 300

__thisTextArea = Text(__root)

__thisMenuBar = Menu(__root)

__thisFileMenu = Menu(__thisMenuBar, tearoff=0)

__thisEditMenu = Menu(__thisMenuBar, tearoff=0)

__thisHelpMenu = Menu(__thisMenuBar, tearoff=0)

__thisScrollBar = Scrollbar(__thisTextArea)

__file = None

def __init__(self,**kwargs):

try:

self.__root.wm_iconbitmap("Notepad.ico")

except:

pass

try:

self.__thisWidth = kwargs['width']

except KeyError:

pass

try:

self.__thisHeight = kwargs['height']

except KeyError:

pass

self.__root.title("Untitled - Notepad")

screenWidth = self.__root.winfo_screenwidth()

screenHeight = self.__root.winfo_screenheight()

left = (screenWidth / 2) - (self.__thisWidth / 2)

top = (screenHeight / 2) - (self.__thisHeight /2)

self.__root.geometry('%dx%d+%d+%d' % (self.__thisWidth,

self.__thisHeight,

left, top))

self.__root.grid_rowconfigure(0, weight=1)

self.__root.grid_columnconfigure(0, weight=1)

self.__thisTextArea.grid(sticky = N + E + S + W)

self.__thisFileMenu.add_command(label="New",

command=self.__newFile)

self.__thisFileMenu.add_command(label="Open",

command=self.__openFile)

self.__thisFileMenu.add_command(label="Save",

command=self.__saveFile)

self.__thisFileMenu.add_separator()

self.__thisFileMenu.add_command(label="Exit",

command=self.__quitApplication)

self.__thisMenuBar.add_cascade(label="File",

menu=self.__thisFileMenu)

self.__thisEditMenu.add_command(label="Cut",

command=self.__cut)

self.__thisEditMenu.add_command(label="Copy",

command=self.__copy)

self.__thisEditMenu.add_command(label="Paste",

command=self.__paste)

self.__thisMenuBar.add_cascade(label="Edit",

menu=self.__thisEditMenu)

self.__thisHelpMenu.add_command(label="About Notepad",

command=self.__showAbout)

self.__thisMenuBar.add_cascade(label="Help",

menu=self.__thisHelpMenu)

self.__root.config(menu=self.__thisMenuBar)

self.__thisScrollBar.pack(side=RIGHT,fill=Y)

self.__thisScrollBar.config(command=self.__thisTextArea.yview)

self.__thisTextArea.config(yscrollcommand=self.__thisScrollBar.set)

def __quitApplication(self):

self.__root.destroy()

def __showAbout(self):

showinfo("Notepad","Mrinal Verma")

def __openFile(self):

self.__file = askopenfilename(defaultextension=".txt",

filetypes=[("All Files","*.*"),

("Text Documents","*.txt")])

if self.__file == "":

self.__file = None

else:

self.__root.title(os.path.basename(self.__file) + " - Notepad")

self.__thisTextArea.delete(1.0,END)

file = open(self.__file,"r")

self.__thisTextArea.insert(1.0,file.read())

file.close()

def __newFile(self):

self.__root.title("Untitled - Notepad")

self.__file = None

self.__thisTextArea.delete(1.0,END)

def __saveFile(self):

if self.__file == None:

self.__file = asksaveasfilename(initialfile='Untitled.txt',

defaultextension=".txt",

filetypes=[("All Files","*.*"),

("Text Documents","*.txt")])

if self.__file == "":

self.__file = None

else:

file = open(self.__file,"w")

file.write(self.__thisTextArea.get(1.0,END))

file.close()

self.__root.title(os.path.basename(self.__file) + " - Notepad")

else:

file = open(self.__file,"w")

file.write(self.__thisTextArea.get(1.0,END))

file.close()

def __cut(self):

self.__thisTextArea.event_generate("<<Cut>>")

def __copy(self):

self.__thisTextArea.event_generate("<<Copy>>")

def __paste(self):

self.__thisTextArea.event_generate("<<Paste>>")

def run(self):

self.__root.mainloop()

notepad = Notepad(width=600,height=400)

notepad.run()


21 Game

def nearestMultipleTo4(num):

if num >= 4:

near = num + (4 - (num % 4))

else:

near = 4

return near

def lose1():

print ("\n\nYOU LOSE !")

print("Better luck next time !")

exit(0)

# checks the numbers are consecutive

def check(xyz):

i = 1

while i<len(xyz):

if (xyz[i]-xyz[i-1])!= 1:

return False

i = i + 1

return True

def start1():

xyz = []

last = 0

while True:

print ("Enter 'F' to take the first chance.")

print("Enter 'S' to take the second chance.")

chance = input('> ')

#First Player

if chance == "F":

while True:

if last == 20:

lose1()

else:

print ("\nYour Turn.")

print ("\nHow many numbers do you wish to enter?")

inp = int(input('> '))

if inp > 0 and inp <= 3:

comp = 4 - inp

else:

print ("Wrong input. You are disqualified from the game.")

lose1()

i, j = 1, 1

print ("Now enter the values")

while i <= inp:

a = input('> ')

a = int(a)

xyz.append(a)

i = i + 1

# store the last element of xyz.

last = xyz[-1]

# check numbers are consecutive

if check(xyz) == True:

if last == 21:

lose1()

else:

#"Computer's turn."

while j <= comp:

xyz.append(last + j)

j = j + 1

print ("Order of inputs after computer's turn is: ")

print (xyz)

last = xyz[-1]

else:

print ("\nYou did not input consecutive integers.")

lose1()

# player takes the second chance

elif chance == "S":

comp = 1

last = 0

while last < 20:

#"Computer's turn"

j = 1

while j <= comp:

xyz.append(last + j)

j = j + 1

print ("Order of inputs after computer's turn is:")

print (xyz)

if xyz[-1] == 20:

lose1()

else:

print ("\nYour turn.")

print ("\nHow many numbers do you wish to enter?")

inp = input('> ')

inp = int(inp)

i = 1

print ("Enter your values")

while i <= inp:

xyz.append(int(input('> ')))

i = i + 1

last = xyz[-1]

if check(xyz) == True:

# print (xyz)

near = nearestMultipleTo4(last)

comp = near - last

if comp == 4:

comp = 3

else:

comp = comp

else:

# if inputs are not consecutive

# automatically disqualified

print ("\nYou did not input consecutive integers.")

# print ("You are disqualified from the game.")

lose1()

print ("\n\nCONGRATULATIONS !!!")

print ("YOU WON !")

exit(0)

else:

print ("wrong choice")

game = True

while game == True:

print ("Player 2 is Computer.")

print("Do you want to play the 21 number game? (Yes / No)")

ans = input('> ')

if ans =='Yes':

start1()

else:

print ("Do you want quit the game?(yes / no)")

nex = input('> ')

if nex == "yes":

print ("You are quitting the game...")

exit(0)

elif nex == "no":

print ("Continuing...")

else:

print ("Wrong choice")


Screen Rotation Application

from tkinter import *

import rotatescreen

def Screen_rotate(temp):

screen = rotatescreen.get_primary_display()

if temp == "up":

screen.set_landscape()

elif temp == "right":

screen.set_portrait_flipped()

elif temp == "down":

screen.set_landscape_flipped()

elif temp == "left":

screen.set_portrait()

master = Tk()

master.geometry("100x100")

master.title("Screen Rotation")

master.configure(bg='light grey')

result = StringVar()

Button(master, text="Up", command=lambda: Screen_rotate(

"up"), bg="white").grid(row=0, column=3)

Button(master, text="Right", command=lambda: Screen_rotate(

"right"), bg="white").grid(row=1, column=6)

Button(master, text="Left", command=lambda: Screen_rotate(

"left"), bg="white").grid(row=1, column=2)

Button(master, text="Down", command=lambda: Screen_rotate(

"down"), bg="white").grid(row=3, column=3)

mainloop()


Application to Search Installed Application

from tkinter import *

import winapps

def app():

for item in winapps.search_installed(e.get()):

name.set(item.name)

version.set(item.version)

Install_date.set(item.install_date)

publisher.set(item.publisher)

uninstall_string.set(item.uninstall_string)

master = Tk()

master.configure(bg='light grey')

name = StringVar()

version = StringVar()

Install_date = StringVar()

publisher = StringVar()

uninstall_string = StringVar()

Label(master, text="Enter App name : ",

bg="light grey").grid(row=0, sticky=W)

Label(master, text="Name : ",

bg="light grey").grid(row=2, sticky=W)

Label(master, text="Version :",

bg="light grey").grid(row=3, sticky=W)

Label(master, text="Install date :",

bg="light grey").grid(row=4, sticky=W)

Label(master, text="publisher :",

bg="light grey").grid(row=5, sticky=W)

Label(master, text="Uninstall string :",

bg="light grey").grid(row=6, sticky=W)

Label(master, text="", textvariable=name,

bg="light grey").grid(row=2, column=1, sticky=W)

Label(master, text="", textvariable=version,

bg="light grey").grid(row=3, column=1, sticky=W)

Label(master, text="", textvariable=Install_date,

bg="light grey").grid(row=4, column=1, sticky=W)

Label(master, text="", textvariable=publisher,

bg="light grey").grid(row=5, column=1, sticky=W)

Label(master, text="", textvariable=uninstall_string,

bg="light grey").grid(row=6, column=1, sticky=W)

e = Entry(master, width=30)

e.grid(row=0, column=1)

b = Button(master, text="Show", command=app, bg="Blue")

b.grid(row=0, column=2, columnspan=2, rowspan=2, padx=5, pady=5,)

mainloop()