(The Main Gaming,Art, Tech And Blockchain Event In Europe)
Zaragoza, Spain 2023 July, 21-22-23th
Solve Problems by Coding Solutions - A Complete solution for python programming
(The Main Gaming,Art, Tech And Blockchain Event In Europe)
Zaragoza, Spain 2023 July, 21-22-23th
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.tag_add("tag_name", "1.0", "end")
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.pointer_size.grid(row=0,column=1,padx=15)
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):
color=colorchooser.askcolor()
self.background.configure(background=color[1])
self.erase= color[1]
def save_drawing(self):
try:
file_ss =filedialog.asksaveasfilename(defaultextension='jpg')
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()
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()
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()
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")