## Blog Pages

### Scientific calculator

import tkinter as tk

from math import *

convert_constant = 1

inverse_convert_constant = 1

btn_params = {'padx': 16, 'pady': 1, 'bd': 4, 'fg': 'white', 'bg': 'black', 'font': ('arial', 18),

'width': 2, 'height': 2, 'relief': 'flat', 'activebackground': "black"}

def fsin(arg):

return sin(arg * convert_constant)

def fcos(arg):

return cos(arg * convert_constant)

def ftan(arg):

return tan(arg * convert_constant)

def arcsin(arg):

return inverse_convert_constant * (asin(arg))

def arccos(arg):

return inverse_convert_constant * (acos(arg))

def arctan(arg):

return inverse_convert_constant * (atan(arg))

class Calculator:

def __init__(self, master):

self.expression = ""

self.recall = ""

self.sum_up = ""

self.text_input = tk.StringVar()

self.master = master

top_frame = tk.Frame(master, width=650, height=10,

bd=10, relief='flat', bg='gray')

top_frame.pack(side=tk.TOP)

bottom_frame = tk.Frame(

master, width=650, height=470, bd=2, relief='flat', bg='black')

bottom_frame.pack(side=tk.BOTTOM)

txt_display = tk.Entry(top_frame, font=('arial', 36), relief='flat', bg='black', fg='white', textvariable=self.text_input, width=60, bd=12, justify='right')

txt_display.pack()

self.btn_left_brack = tk.Button(

bottom_frame, **btn_params, text="(", border=1, command=lambda: self.btn_click('('))

self.btn_left_brack.grid(row=0, column=0)

self.btn_right_brack = tk.Button(

bottom_frame, **btn_params, text=")", command=lambda: self.btn_click(')'))

self.btn_right_brack.grid(row=0, column=1)

self.btn_exp = tk.Button(

bottom_frame, **btn_params, text="exp", command=lambda: self.btn_click('exp('))

self.btn_exp.grid(row=0, column=2)

self.btn_pi = tk.Button(

bottom_frame, **btn_params, text="π", command=lambda: self.btn_click('pi'))

self.btn_pi.grid(row=0, column=3)

self.btn_sqrt = tk.Button(

bottom_frame, **btn_params, text="sqrt", command=lambda: self.btn_click('sqrt('))

self.btn_sqrt.grid(row=0, column=4)

self.btn_clear = tk.Button(

bottom_frame, **btn_params, text="C", command=self.btn_clear_all)

self.btn_clear.grid(row=0, column=5)

self.btn_del = tk.Button(

bottom_frame, **btn_params, text="AC", command=self.btn_clear1)

self.btn_del.grid(row=0, column=6)

self.btn_change_sign = tk.Button(

bottom_frame, **btn_params, text="+/-", command=self.change_signs)

self.btn_change_sign.grid(row=0, column=7)

self.btn_div = tk.Button(

bottom_frame, **btn_params, text="/", command=lambda: self.btn_click('/'))

self.btn_div.grid(row=0, column=8)

self.btn_Deg = tk.Button(bottom_frame, **btn_params, activeforeground='gray', text="Deg", command=self.convert_deg)

self.btn_Deg.grid(row=1, column=0)

self.cube = tk.Button(bottom_frame, **btn_params, text=u"x\u00B3", command=lambda: self.btn_click('**3'))

self.cube.grid(row=1, column=2)

self.btn_abs = tk.Button(

bottom_frame, **btn_params, text="abs", command=lambda: self.btn_click('abs' + '('))

self.btn_abs.grid(row=1, column=3)

self.btn_MC = tk.Button(

bottom_frame, **btn_params, text="MC", command=self.memory_clear)

self.btn_MC.grid(row=1, column=4)

self.btn_7 = tk.Button(bottom_frame, **btn_params, text="7", command=lambda: self.btn_click(7))

self.btn_7.configure(activebackground="black", bg='black')

self.btn_7.grid(row=1, column=5)

self.btn_8 = tk.Button(bottom_frame, **btn_params, text="8", command=lambda: self.btn_click(8))

self.btn_8.configure(activebackground="black", bg='black')

self.btn_8.grid(row=1, column=6)

self.btn_9 = tk.Button(bottom_frame, **btn_params, text="9", command=lambda: self.btn_click(9))

self.btn_9.configure(activebackground="black", bg='black')

self.btn_9.grid(row=1, column=7)

self.btn_mult = tk.Button(bottom_frame, **btn_params, text="x", command=lambda: self.btn_click('*'))

self.btn_mult.grid(row=1, column=8)

self.btn_sin = tk.Button(

bottom_frame, **btn_params, text="sin", command=lambda: self.btn_click('fsin('))

self.btn_sin.grid(row=2, column=0)

self.btn_cos = tk.Button(

bottom_frame, **btn_params, text="cos", command=lambda: self.btn_click('fcos('))

self.btn_cos.grid(row=2, column=1)

self.btn_tan = tk.Button(bottom_frame, **btn_params, text="tan", command=lambda: self.btn_click('ftan('))

self.btn_tan.grid(row=2, column=2)

self.btn_log = tk.Button(bottom_frame, **btn_params, text="log", command=lambda: self.btn_click('log('))

self.btn_log.grid(row=2, column=3)

self.btn_MR = tk.Button(bottom_frame, **btn_params, text="MR", command=self.memory_recall)

self.btn_MR.grid(row=2, column=4)

self.btn_4 = tk.Button(bottom_frame, **btn_params, text="4", command=lambda: self.btn_click(4))

self.btn_4.configure(activebackground="black", bg='black')

self.btn_4.grid(row=2, column=5)

self.btn_5 = tk.Button(bottom_frame, **btn_params, text="5", command=lambda: self.btn_click(5))

self.btn_5.configure(activebackground="black", bg='black')

self.btn_5.grid(row=2, column=6)

self.btn_6 = tk.Button(bottom_frame, **btn_params, text="6", command=lambda: self.btn_click(6))

self.btn_6.configure(activebackground="black", bg='black')

self.btn_6.grid(row=2, column=7)

self.btnSub = tk.Button(bottom_frame, **btn_params, text="-", command=lambda: self.btn_click('-'))

self.btnSub.grid(row=2, column=8)

self.btn_sin_inverse = tk.Button(bottom_frame, **btn_params, text=u"sin-\u00B9", command=lambda: self.btn_click('arcsin('))

self.btn_sin_inverse.grid(row=3, column=0)

self.btn_cos_inverse = tk.Button(bottom_frame, **btn_params, text=u"cos-\u00B9", command=lambda: self.btn_click('arccos('))

self.btn_cos_inverse.grid(row=3, column=1)

self.btn_tan_inverse = tk.Button(bottom_frame, **btn_params, text=u"tan-\u00B9", command=lambda: self.btn_click('arctan('))

self.btn_tan_inverse.grid(row=3, column=2)

self.btn_ln = tk.Button(bottom_frame, **btn_params, text="ln", command=lambda: self.btn_click('log1p('))

self.btn_ln.grid(row=3, column=3)

self.btn_M_plus = tk.Button(bottom_frame, **btn_params, text="M+", command=self.memory_add)

self.btn_M_plus.grid(row=3, column=4)

self.btn_1 = tk.Button(bottom_frame, **btn_params, text="1", command=lambda: self.btn_click(1))

self.btn_1.configure(activebackground="black", bg='black')

self.btn_1.grid(row=3, column=5)

self.btn_2 = tk.Button(bottom_frame, **btn_params, text="2", command=lambda: self.btn_click(2))

self.btn_2.configure(activebackground="black", bg='black')

self.btn_2.grid(row=3, column=6)

self.btn_3 = tk.Button(bottom_frame, **btn_params, text="3", command=lambda: self.btn_click(3))

self.btn_3.configure(activebackground="black", bg='black')

self.btn_3.grid(row=3, column=7)

bottom_frame, **btn_params, text="+", command=lambda: self.btn_click('+'))

self.btn_fact = tk.Button(bottom_frame, **btn_params, text="n!", command=lambda: self.btn_click('factorial('))

self.btn_fact.grid(row=4, column=0)

self.btn_sqr = tk.Button(bottom_frame, **btn_params, text=u"x\u00B2", command=lambda: self.btn_click('**2'))

self.btn_sqr.grid(row=4, column=1)

self.btn_power = tk.Button(bottom_frame, **btn_params, text="x^y", command=lambda: self.btn_click('**'))

self.btn_power.grid(row=4, column=2)

self.btn_ans = tk.Button(bottom_frame, **btn_params, text="ans", command=self.answer)

self.btn_ans.grid(row=4, column=3)

self.btn_comma = tk.Button(bottom_frame, **btn_params, text=",", command=lambda: self.btn_click(','))

self.btn_comma.grid(row=4, column=4)

self.btn_0 = tk.Button(bottom_frame, **btn_params, text="0", command=lambda: self.btn_click(0))

self.btn_0.configure(activebackground="black", bg='black', width=7, bd=5)

self.btn_0.grid(row=4, column=5, columnspan=2)

self.btn_eq = tk.Button(bottom_frame, **btn_params, text="=", command=self.btn_equal)

self.btn_eq.configure(bg='Gray', activebackground='#009999')

self.btn_eq.grid(row=4, column=7)

self.btn_dec = tk.Button(bottom_frame, **btn_params, text=".", command=lambda: self.btn_click('.'))

self.btn_dec.grid(row=4, column=8)

def btn_click(self, expression_val):

if len(self.expression) >= 23:

self.expression = self.expression

self.text_input.set(self.expression)

else:

self.expression = self.expression + str(expression_val)

self.text_input.set(self.expression)

def btn_clear1(self):

self.expression = self.expression[:-1]

self.text_input.set(self.expression)

def change_signs(self):

self.expression = self.expression + '-'

self.text_input.set(self.expression)

def memory_clear(self):

self.recall = ""

self.recall = self.recall + '+' + self.expression

self.text_input.set(self.expression)

def memory_recall(self):

if self.expression == "":

self.text_input.set('0' + self.expression + self.recall)

else:

self.text_input.set(self.expression + self.recall)

def convert_deg(self):

global convert_constant

global inverse_convert_constant

convert_constant = pi / 180

inverse_convert_constant = 180 / pi

self.btn_Deg["foreground"] = 'RED'

global convert_constant

global inverse_convert_constant

convert_constant = 1

inverse_convert_constant = 1

self.btn_Deg["foreground"] = 'white'

def btn_clear_all(self):

self.expression = ""

self.text_input.set("")

def btn_equal(self):

self.sum_up = str(eval(self.expression))

self.text_input.set(self.sum_up)

self.expression = self.sum_up

root = tk.Tk()

b = Calculator(root)

root.title("Scientific Calculator!")

root.geometry("650x490+50+50")

root.resizable(False, False)

root.mainloop()

### music player

import pygame

from pygame import mixer

pygame.init()

mixer.init()

screen = pygame.display.set_mode((600, 400))

mixer.music.play()

print("Press 'p' to pause 'r' to resume")

print("Press 'q' to quit")

running = True

while running:

for event in pygame.event.get():

if event.type == pygame.QUIT:

running = False

if event.type == pygame.KEYDOWN:

if event.key == pygame.K_p:

mixer.music.pause()

if event.key == pygame.K_r:

mixer.music.unpause()

if event.key == pygame.K_q:

running = False

quit()

### Voice Assistant

import pyttsx3

import speech_recognition as sr

def take_commands():

r = sr.Recognizer()

with sr.Microphone() as source:

print('Listening')

r.pause_threshold = 0.7

audio = r.listen(source)

try:

print("Recognizing")

print("the query is printed='", Query, "'")

except Exception as e:

print(e)

print("Say that again sir")

return "None"

return Query

def Speak(audio):

engine = pyttsx3.init()

engine.say(audio)

engine.runAndWait()

if __name__ == '__main__':

while True:

command = take_commands()

if "exit" in command:

Speak("Sure sir! as your wish, bye")

break

if "welcome" in command:

Speak("hi welcome to python for engineers")

if "python" in command:

Speak("a complete solution for python programming")

### Typing Speed Test Application

from tkinter import *

import ctypes

import random

import tkinter

ctypes.windll.shcore.SetProcessDpiAwareness(1)

storage = Tk()

storage.title('Typing Speed Test')

storage.geometry('1400x700')

def handlingLabels():

random_selection = [

'Software engineering is the branch of computer science that deals with the design, development, testing, and maintenance of software applications. Software engineers apply engineering principles and knowledge of programming languages to build software solutions for end users.',

'A web developer is a programmer who develops World Wide Web applications using a client–server model. The applications typically use HTML, CSS, and JavaScript in the client, and any general-purpose programming language in the server. HTTP is used for communications between client and server.'

]

text = random.choice(random_selection).lower()

splitPoint = 0

global nameLabelLeft

nameLabelLeft = Label(storage, text=text[0:splitPoint], fg='green')

nameLabelLeft.place(relx=0.5, rely=0.5, anchor=E)

global nameLabelRight

nameLabelRight = Label(storage, text=text[splitPoint:])

nameLabelRight.place(relx=0.5, rely=0.5, anchor=W)

global currentAlphabetLabel

currentAlphabetLabel = Label(storage, text=text[splitPoint], fg='grey')

currentAlphabetLabel.place(relx=0.5, rely=0.6, anchor=N)

global secondsLeft

headingLabel = Label(storage, text=f'CopyAssignment - Typing Speed Test', fg='blue')

secondsLeft = Label(storage, text=f'0 Seconds', fg='red')

secondsLeft.place(relx=0.5, rely=0.4, anchor=S)

global writeAble

writeAble = True

storage.bind('<Key>', handlekeyPress)

global secondsPassed

secondsPassed = 0

storage.after(60000, stopGame)

def stopGame():

global writeAble

writeAble = False

amountWords = len(nameLabelLeft.cget('text').split(' '))

secondsLeft.destroy()

currentAlphabetLabel.destroy()

nameLabelRight.destroy()

nameLabelLeft.destroy()

global labelOfResult

labelOfResult = Label(storage, text=f'Words per Minute (WPM): {amountWords}', fg='black')

labelOfResult.place(relx=0.5, rely=0.4, anchor=CENTER)

global showcaseResults

showcaseResults = Button(storage, text=f'Retry', command=restartGame)

showcaseResults.place(relx=0.5, rely=0.6, anchor=CENTER)

def restartGame():

labelOfResult.destroy()

showcaseResults.destroy()

handlingLabels()

global secondsPassed

secondsPassed += 1

secondsLeft.configure(text=f'{secondsPassed} Seconds')

if writeAble:

def handlekeyPress(event=None):

try:

if event.char.lower() == nameLabelRight.cget('text')[0].lower():

nameLabelRight.configure(text=nameLabelRight.cget('text')[1:])

nameLabelLeft.configure(text=nameLabelLeft.cget('text') + event.char.lower())

currentAlphabetLabel.configure(text=nameLabelRight.cget('text')[0])

except tkinter.TclError:

pass

handlingLabels()

storage.mainloop()

### Open Games Con

(The Main Gaming,Art, Tech And Blockchain Event In Europe)

Zaragoza, Spain 2023 July, 21-22-23th

### Drawing Application

from tkinter import *

from tkinter.ttk import Scale

from tkinter import colorchooser,filedialog,messagebox

import PIL.ImageGrab as ImageGrab

class Draw():

def __init__(self,root):

self.root =root

self.root.title("Painter")

self.root.configure(background="white")

self.pointer= "black"

self.erase="white"

text=Text(root)

text.tag_configure("tag_name", justify='center', font=('arial',25),background='#292826',foreground='orange')

text.insert("1.0", "Drawing Application ")

text.pack()

self.pick_color = LabelFrame(self.root,text='Colors',font =('arial',15),bd=5,relief=RIDGE,bg="white")

self.pick_color.place(x=0,y=40,width=90,height=185)

colors = ['blue','red','green', 'orange','violet','black','yellow','purple','pink','gold','brown','indigo']

i=j=0

for color in colors:

Button(self.pick_color,bg=color,bd=2,relief=RIDGE,width=3,command=lambda col=color:self.select_color(col)).grid(row=i,column=j)

i+=1

if i==6:

i=0

j=1

self.eraser_btn= Button(self.root,text="Eraser",bd=4,bg='white',command=self.eraser,width=9,relief=RIDGE)

self.eraser_btn.place(x=0,y=197)

self.clear_screen= Button(self.root,text="Clear Screen",bd=4,bg='white',command= lambda : self.background.delete('all'),width=9,relief=RIDGE)

self.clear_screen.place(x=0,y=227)

self.save_btn= Button(self.root,text="ScreenShot",bd=4,bg='white',command=self.save_drawing,width=9,relief=RIDGE)

self.save_btn.place(x=0,y=257)

self.bg_btn= Button(self.root,text="Background",bd=4,bg='white',command=self.canvas_color,width=9,relief=RIDGE)

self.bg_btn.place(x=0,y=287)

self.pointer_frame= LabelFrame(self.root,text='size',bd=5,bg='white',font=('arial',15,'bold'),relief=RIDGE)

self.pointer_frame.place(x=0,y=320,height=200,width=70)

self.pointer_size =Scale(self.pointer_frame,orient=VERTICAL,from_ =48 , to =0, length=168)

self.pointer_size.set(1)

self.background = Canvas(self.root,bg='white',bd=5,relief=GROOVE,height=470,width=680)

self.background.place(x=80,y=40)

self.background.bind("<B1-Motion>",self.paint)

def paint(self,event):

x1,y1 = (event.x-2), (event.y-2)

x2,y2 = (event.x+2), (event.y+2)

self.background.create_oval(x1,y1,x2,y2,fill=self.pointer,outline=self.pointer,width=self.pointer_size.get())

def select_color(self,col):

self.pointer = col

def eraser(self):

self.pointer= self.erase

def canvas_color(self):

self.background.configure(background=color[1])

self.erase= color[1]

def save_drawing(self):

try:

x=self.root.winfo_rootx() + self.background.winfo_x()

y=self.root.winfo_rooty() + self.background.winfo_y()

x1= x + self.background.winfo_width()

y1= y + self.background.winfo_height()

ImageGrab.grab().crop((x , y, x1, y1)).save(file_ss)

messagebox.showinfo('Screenshot Successfully Saved as' + str(file_ss))

except:

print("Error in saving the screenshot")

if __name__ =="__main__":

root = Tk()

p= Draw(root)

root.mainloop()