Posts

Showing posts from June, 2024

Making Screen Pet Using Python

Image
 # Making Screen Pet Using Python..... from tkinter import HIDDEN , NORMAL , Tk , Canvas def toggle_eyes ():     current_color = c . itemcget ( eye_left , 'fill' )     new_color = c .body_color if current_color == 'white' else 'white'     current_state = c . itemcget ( pupil_left , 'state' )     new_state = NORMAL if current_state == HIDDEN else HIDDEN     c . itemconfigure ( pupil_left , state = new_state )     c . itemconfigure ( pupil_right , state = new_state )     c . itemconfigure ( eye_left , fill = new_color )     c . itemconfigure ( eye_right , fill = new_color ) def blink ():     toggle_eyes ()     root . after ( 250 , toggle_eyes )     root . after ( 3000 , blink ) def toggle_pupils ():     if not c .eyes_crossed:         c . move ( pupil_left , 10 , - 5 )         c . move ( pupil_right ...

Making Traffic Signal Using Python

Image
 #Making Traffic Signal Using Python..... import turtle as t t . bgcolor ( 'light blue' ) t . speed ( 'slowest' ) t . hideturtle () t . delay ( 0 ) t . pencolor ( '' ) t . goto ( - 150 , 100 ) t . fillcolor ( 'black' ) t . begin_fill () t . pencolor ( 'gray' ) t . forward ( 150 ) t . right ( 90 ) t . forward ( 325 ) t . right ( 90 )   t . forward ( 150 ) t . right ( 90 ) t . forward ( 325 ) t . right ( 90 ) t . end_fill () t . delay ( 0 ) t . pencolor ( '' ) t . goto ( - 75 , 0 ) t . fillcolor ( 'gray' ) t . begin_fill () t . pencolor ( 'white' ) t . circle ( 35 ) t . end_fill () t . delay ( 0 ) t . pencolor ( '' ) t . goto ( - 75 , - 100 ) t . fillcolor ( 'gray' ) t . begin_fill () t . pencolor ( 'white' ) t . circle ( 35 ) t . end_fill () t . delay ( 0 ) t . pencolor ( '' ) t . goto ( - 75 , - 200 ) t . fillcolor ( 'gray' ) t . begin_fill () t . pencolor ( 'white' ) t . ...

Making Rainbow Using Python

Image
 # Making Rainbow Using Python..... # Import turtle package import turtle # Creating a turtle screen object sc = turtle . Screen () # Creating a turtle object(pen) pen = turtle . Turtle () # Defining a method to form a semicircle # with a dynamic radius and color def semi_circle ( col , rad , val ):     # Set the fill color of the semicircle     pen . color ( col )     # Draw a circle     pen . circle ( rad , - 180 )     # Move the turtle to air     pen . up ()     # Move the turtle to a given position     pen . setpos ( val , 0 )     # Move the turtle to the ground     pen . down ()     pen . right ( 180 ) # Set the colors for drawing col = [ 'violet' , 'indigo' , 'blue' ,     'green' , 'yellow' , 'orange' , 'red' ] # Setup the screen features sc . setup ( 500 , 500 ) # Set the screen color to black sc . bgcolor ( 'black' ) # Setup the turtle features pen...

Making Snake Game Using Python

Image
# Making Snake Game Using Python..... import turtle import time import random # Create a Snake-Game using Turtle in Python delay = 0.1 score = 0 high_score = 0 wn = turtle . Screen () wn . title ( "Snake Game" ) wn . bgcolor ( "black" ) wn . setup ( width = 600 , height = 600 ) wn . tracer ( 0 ) head = turtle . Turtle () head . shape ( "circle" ) head . color ( "white" ) head . penup () head . goto ( 0 , 0 ) head .direction = "stop" food = turtle . Turtle () colors = random . choice ([ 'red' , 'green' , 'yellow' ]) shapes = random . choice ([ 'square' , 'triangle' , 'circle' ]) food . speed ( 0 ) food . shape ( shapes ) food . color ( colors ) food . penup () food . goto ( 0 , 100 ) pen = turtle . Turtle () pen . speed ( 0 ) pen . shape ( "circle" ) pen . color ( "white" ) pen . penup () pen . hideturtle () pen . goto ( 0 , 250 ) pen . write ( ...