How to make SPACE INVADERS using Pygame in Python

DO MAKE SURE TO VISIT MY CHANNEL :) import pygame, random pygame.init() health = 100 score = 0 display = pygame.display.set_mode((1200, 673)) bg = pygame.image.load("space.png") player = pygame.image.load("player.png") enemy = pygame.image.load("enemy.png") bullet = pygame.image.load("bullet (2).png") bullet_2 = pygame.image.load("bullet (2).png") bullet_3 = pygame.image.load("bullet (2).png") player_x = 550 player_y = 500 player_bullet = pygame.image.load("bullet (2).png") player_bullet_x = player_x-10 player_bullet_y = player_y+20 enemy_x = random.randint(0, 1000) enemy_2_x = random.randint(0, 1000) enemy_3_x  = random.randint(0, 1000) enemy_y = 0 enemy_bullet_x = enemy_x+17 enemy_bullet_2_x = enemy_2_x+17 enemy_bullet_3_x = enemy_3_x+17 enemy_bullet_y = enemy_y+25 running = True while running:     font = pygame.font.SysFont(None, 40 )     display.blit(bg, (0, 0))     text = font.render(f'Score: {score}', T...

How to make a Likes & Dislikes counter using Tkinter in Python

 


Import tkinter
    from tkinter import *
Make a window
from tkinter import *

root = Tk()
root.geometry("500x500")

root.mainloop()
Make two buttons
from tkinter import *

root = Tk()
root.geometry("500x500")

like_btn = Button(root)
like_btn.pack()

dislike_btn = Button(root)
dislike_btn.pack()

root.mainloop()
Import the images
from tkinter import *

root = Tk()
root.geometry("500x500")

like_img = PhotoImage(file="like.png")
dislike_img = PhotoImage(file = "dislike.png")

like_btn = Button(root)
like_btn.pack()

dislike_btn = Button(root)
dislike_btn.pack()

root.mainloop()
Add these images to the buttons
from tkinter import *

root = Tk()
root.geometry("500x500")

like_img = PhotoImage(file="like.png")
dislike_img = PhotoImage(file = "dislike.png")

like_btn = Button(root, image=like_img)
like_btn.pack()

dislike_btn = Button(root, image=dislike_img)
dislike_btn.pack()

root.mainloop()
Make two variables
from tkinter import *

root = Tk()
root.geometry("500x500")

like_img = PhotoImage(file="like.png")
dislike_img = PhotoImage(file = "dislike.png")

likes = 0
dislikes = 0
	

like_btn = Button(root, image=like_img)
like_btn.pack()

dislike_btn = Button(root, image=dislike_img)
dislike_btn.pack()

root.mainloop()
Make two functions
from tkinter import *

root = Tk()
root.geometry("500x500")

like_img = PhotoImage(file="like.png")
dislike_img = PhotoImage(file = "dislike.png")

likes = 0
dislikes = 0

def like():
	pass

def dislike():
	pass

like_btn = Button(root, image=like_img)
like_btn.pack()

dislike_btn = Button(root, image=dislike_img)
dislike_btn.pack()

root.mainloop()
Make two labels
from tkinter import *

root = Tk()
root.geometry("500x500")

like_img = PhotoImage(file="like.png")
dislike_img = PhotoImage(file = "dislike.png")

likes = 0
dislikes = 0

def like():
	pass

def dislike():
	pass

like_lbl = Label(root, text=f"Likes: {likes}")
like_lbl.pack()

dislike_lbl = Label(root, text=f"Dislikes: {dislikes}")
dislike_lbl.pack()

like_btn = Button(root, image=like_img)
like_btn.pack()

dislike_btn = Button(root, image=dislike_img)
dislike_btn.pack()

root.mainloop()
Add 1 to the variable when its function gets called
from tkinter import *

root = Tk()
root.geometry("500x500")

like_img = PhotoImage(file="like.png")
dislike_img = PhotoImage(file = "dislike.png")

likes = 0
dislikes = 0

def like():
	likes += 1

def dislike():
	dislikes += 1

like_lbl = Label(root, text=f"Likes: {likes}")
like_lbl.pack()

dislike_lbl = Label(root, text=f"Dislikes: {dislikes}")
dislike_lbl.pack()

like_btn = Button(root, image=like_img)
like_btn.pack()

dislike_btn = Button(root, image=dislike_img)
dislike_btn.pack()

root.mainloop()
Now update the respective label so it can change its text
from tkinter import *

root = Tk()
root.geometry("500x500")

like_img = PhotoImage(file="like.png")
dislike_img = PhotoImage(file = "dislike.png")

likes = 0
dislikes = 0

def like():
	likes += 1
	like_lbl.config(text=f"Likes: {likes}")

def dislike():
	dislikes += 1
	dislikes_lbl.config(text=f"Dislikes: {dislikes}")

like_lbl = Label(root, text=f"Likes: {likes}")
like_lbl.pack()

dislike_lbl = Label(root, text=f"Dislikes: {dislikes}")
dislike_lbl.pack()

like_btn = Button(root, image=like_img)
like_btn.pack()

dislike_btn = Button(root, image=dislike_img)
dislike_btn.pack()

root.mainloop()
Finally, assign the function to its respective button
from tkinter import *

root = Tk()
root.geometry("500x500")

like_img = PhotoImage(file="like.png")
dislike_img = PhotoImage(file = "dislike.png")

likes = 0
dislikes = 0

def like():
	likes += 1
	like_lbl.config(text=f"Likes: {likes}")

def dislike():
	dislikes += 1
	dislikes_lbl.config(text=f"Dislikes: {dislikes}")

like_lbl = Label(root, text=f"Likes: {likes}")
like_lbl.pack()

dislike_lbl = Label(root, text=f"Dislikes: {dislikes}")
dislike_lbl.pack()

like_btn = Button(root, image=like_img, command=like)
like_btn.pack()

dislike_btn = Button(root, image=dislike_img, command=dislike)
dislike_btn.pack()

root.mainloop()

Comments

Popular posts from this blog

How to make Chess game using Python, Pygame

How to make SPACE INVADERS using Pygame in Python

How To Make a Car Game Using Python