memory game

from random import *

from turtle import *

screen = Screen()

screen.bgcolor("yellow")

def Square(x, y):

    up()

    goto(x, y)

    down()

    color('white', 'red')

    begin_fill()

    for count in range(4):

        forward(50)

        left(90)

    end_fill()

def numbers(x, y):

    return int((x + 200) // 50 + ((y + 200) // 50) * 8)

def Coordinates(count):

    return (count % 8) * 50 - 200, (count // 8) * 50 - 200

def click(x, y):

    spot = numbers(x, y)

    mark = state['mark']

    if mark is None or mark == spot or tiles[mark] != tiles[spot]:

        state['mark'] = spot

    else:

        hide[spot] = False

        hide[mark] = False

        state['mark'] = None

def draw():

    clear()

    goto(0, 0)

    stamp()

    for count in range(64):

        if hide[count]:

            x, y = Coordinates(count)

            Square(x, y)

    mark = state['mark']

    if mark is not None and hide[mark]:

        x, y = Coordinates(mark)

        up()

        goto(x + 2, y)

        color('white')

        write(tiles[mark], font=('Arial', 30, 'normal'))

    update()

    ontimer(draw, 10)

tiles = list(range(32)) * 2

state = {'mark': None}

hide = [True] * 64

shuffle(tiles)

tracer(False)

onscreenclick(click)

draw()

done()


Background remover app

import tkinter as tk

from rembg import remove

from PIL import Image

from tkinter import filedialog

from PIL import Image

import os

from tkinter import messagebox

top = tk.Tk()

top.geometry("400x400")

top.title('Background Remover')

filename = ''

def upload_file():

    global filename

    f_types = [('Jpg Files', '*.jpg')]

    filename = filedialog.askopenfilename(filetypes=f_types)

    if len(filename) > 0:

        b1.config(state='disabled')

def Convert(image_name):

    current_working_directory = os.getcwd()

    input_path = filename

    output_path = f'{current_working_directory}\{image_name}.png'

    image_input = Image.open(input_path)

    output = remove(image_input)

    output.save(output_path)

    messagebox.showinfo('Success', 'Image background successfully removed')

    top.destroy()

my_font1 = ('times', 18, 'bold')

l1 = tk.Label(top, text='Background Removal App', width=30, font=my_font1)

l1.grid(row=1, column=1)

b1 = tk.Button(top, text='Select here', height=2, font=('Arial', 20), bg='green', fg='white', command=lambda: upload_file())

b1.grid(row=2, column=1, pady=20)

image_name = tk.StringVar(top)

image_name.set('enter file name')

e1 = tk.Entry(top, textvariable=image_name)

e1.grid(row=3, column=1, pady=20)

b2 = tk.Button(top, text='Convert now', height=2, font=('Arial', 20), bg='green', fg='white', command=lambda: Convert(image_name.get()))

b2.grid(row=4, column=1, pady=20)

top.mainloop()

File Explorer

from tkinter import *

from tkinter import filedialog

def browseFiles():

    filename = filedialog.askopenfilename(initialdir = "/",

                                        title = "Select a File",

                                        filetypes = (("Text files",

                                                        "*.txt*"),

                                                    ("all files",

                                                        "*.*")))

    label_file_explorer.configure(text="File Opened: "+filename)                                                                                              

window = Tk()

window.title('File Explorer')

window.geometry("500x500")

window.config(background = "white")

label_file_explorer = Label(window,

                            text = "File Explorer using Tkinter",

                            width = 100, height = 4,

                            fg = "blue")

button_explore = Button(window,

                        text = "Browse Files",

                        command = browseFiles)

button_exit = Button(window,

                    text = "Exit",

                    command = exit)

label_file_explorer.grid(column = 1, row = 1)

button_explore.grid(column = 1, row = 2)

button_exit.grid(column = 1,row = 3)

window.mainloop()


Screenshot using pyscreenshot

The simplest way of taking a screenshot using pyscreenshot module

Install the package:

               pip install pyscreenshot 


import pyscreenshot

image = pyscreenshot.grab()

image.show()

image.save("screenshot.png")


Flames Checker

def rmv_match_char(list1, list2):

    for i in range(len(list1)):

        for j in range(len(list2)):

            if list1[i] == list2[j]:

                c = list1[i]

                list1.remove(c)

                list2.remove(c)

                list3 = list1 + ["*"] + list2

                return [list3, True]

    list3 = list1 + ["*"] + list2

    return [list3, False]

if __name__ == "__main__":

    p1 = input("Player 1 name : ")

    p1 = p1.lower()

    p1.replace(" ", "")

    p1_list = list(p1)

    p2 = input("Player 2 name : ")

    p2 = p2.lower()

    p2.replace(" ", "")

    p2_list = list(p2)

    proceed = True

    while proceed:

        ret_list = rmv_match_char(p1_list, p2_list)

        con_list = ret_list[0]

        proceed = ret_list[1]

        star_index = con_list.index("*")

        p1_list = con_list[: star_index]

        p2_list = con_list[star_index + 1:]

    count = len(p1_list) + len(p2_list)

    result = ["Friends", "Love", "Affection", "Marriage", "Enemy", "Siblings"]

    while len(result) > 1:

        split_index = (count % len(result) - 1)

        if split_index >= 0:

            right = result[split_index + 1:]

            left = result[: split_index]

            result = right + left

        else:

            result = result[: len(result) - 1]

    print("Relationship status :", result[0])