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


Generating prime numbers using the sieve of eratosthenes algorithm

def sieve_of_eratosthenes(n):

    primes = [True] * (n + 1)

    primes[0] = primes[1] = False


    for i in range(2, int(n ** 0.5) + 1):

        if primes[i]:

            for j in range(i ** 2, n + 1, i):

                primes[j] = False


    return [i for i in range(2, n + 1) if primes[i]]


# Example usage

n = 100

primes = sieve_of_eratosthenes(n)

print("The prime numbers up to", n, "are:", primes)

Sierpinski triangle fractal using turtle graphics

import turtle

def sierpinski(length, depth):

    if depth == 0:

        for i in range(3):

            turtle.forward(length)

            turtle.left(120)

    else:

        sierpinski(length / 2, depth - 1)

        turtle.forward(length / 2)

        sierpinski(length / 2, depth - 1)

        turtle.backward(length / 2)

        turtle.left(60)

        turtle.forward(length / 2)

        turtle.right(60)

        sierpinski(length / 2, depth - 1)

        turtle.left(60)

        turtle.backward(length / 2)

        turtle.right(60)

turtle.speed(0)

turtle.hideturtle()

turtle.penup()

turtle.goto(-200, -200)

turtle.pendown()

sierpinski(400, 5)

turtle.exitonclick()


Pong game

import turtle

sc = turtle.Screen()

sc.title("Pong game")

sc.bgcolor("white")

sc.setup(width=1000, height=600)

left_pad = turtle.Turtle()

left_pad.speed(0)

left_pad.shape("square")

left_pad.color("black")

left_pad.shapesize(stretch_wid=6, stretch_len=2)

left_pad.penup()

left_pad.goto(-400, 0)

right_pad = turtle.Turtle()

right_pad.speed(0)

right_pad.shape("square")

right_pad.color("black")

right_pad.shapesize(stretch_wid=6, stretch_len=2)

right_pad.penup()

right_pad.goto(400, 0)

hit_ball = turtle.Turtle()

hit_ball.speed(40)

hit_ball.shape("circle")

hit_ball.color("blue")

hit_ball.penup()

hit_ball.goto(0, 0)

hit_ball.dx = 5

hit_ball.dy = -5

left_player = 0

right_player = 0

sketch = turtle.Turtle()

sketch.speed(0)

sketch.color("blue")

sketch.penup()

sketch.hideturtle()

sketch.goto(0, 260)

sketch.write("Left_player : 0 Right_player: 0",

            align="center", font=("Courier", 24, "normal"))

def paddleaup():

    y = left_pad.ycor()

    y += 20

    left_pad.sety(y)

def paddleadown():

    y = left_pad.ycor()

    y -= 20

    left_pad.sety(y)

def paddlebup():

    y = right_pad.ycor()

    y += 20

    right_pad.sety(y)

def paddlebdown():

    y = right_pad.ycor()

    y -= 20

    right_pad.sety(y)

sc.listen()

sc.onkeypress(paddleaup, "e")

sc.onkeypress(paddleadown, "x")

sc.onkeypress(paddlebup, "Up")

sc.onkeypress(paddlebdown, "Down")

while True:

    sc.update()

    hit_ball.setx(hit_ball.xcor()+hit_ball.dx)

    hit_ball.sety(hit_ball.ycor()+hit_ball.dy)

    if hit_ball.ycor() > 280:

        hit_ball.sety(280)

        hit_ball.dy *= -1

    if hit_ball.ycor() < -280:

        hit_ball.sety(-280)

        hit_ball.dy *= -1

    if hit_ball.xcor() > 500:

        hit_ball.goto(0, 0)

        hit_ball.dy *= -1

        left_player += 1

        sketch.clear()

        sketch.write("Left_player : {} Right_player: {}".format(

                    left_player, right_player), align="center",

                    font=("Courier", 24, "normal"))

    if hit_ball.xcor() < -500:

        hit_ball.goto(0, 0)

        hit_ball.dy *= -1

        right_player += 1

        sketch.clear()

        sketch.write("Left_player : {} Right_player: {}".format(

                                left_player, right_player), align="center",

                                font=("Courier", 24, "normal"))


    if (hit_ball.xcor() > 360 and hit_ball.xcor() < 370) and (hit_ball.ycor() < right_pad.ycor()+40 and hit_ball.ycor() > right_pad.ycor()-40):

        hit_ball.setx(360)

        hit_ball.dx*=-1

        

    if (hit_ball.xcor()<-360 and hit_ball.xcor() >- 370) and (hit_ball.ycor() < left_pad.ycor()+40 and hit_ball.ycor() > left_pad.ycor()-40):

        hit_ball.setx(-360)

        hit_ball.dx*=-1