Monday, July 25, 2022

Animation in tkinter



                              Space.png                                            UFO.png 

from tkinter import *

from time import sleep

from random import randint


WIDTH, HEIGHT = 500, 500

velX, velY = randint(-3, 3), randint(-3, 3)


win = Tk()

win.geometry("500x500")


canvas = Canvas(win, width=WIDTH, height=HEIGHT, bg="light blue")

canvas.place(x=0, y=0)


picSpace = PhotoImage(file="Space.png")

imgSpace = canvas.create_image(0, 0, image=picSpace, anchor=NW)


picUFO = PhotoImage(file="UFO.png")

imgUFO = canvas.create_image(10, 10, image=picUFO, anchor=NW)

imgWidth, imgHeight = picUFO.width(), picUFO.height()


running = True

while running:

  velX, velY = randint(-3, 3), randint(-3, 3)

  print(velX, velY)

  coordinates = canvas.coords(imgUFO)

  if(coordinates[0] >= (WIDTH - imgWidth) or coordinates[0] < 0):

    velX = -velX

  if(coordinates[1] >= (HEIGHT - imgHeight) or coordinates[1] < 0):

    velY = -velY

  canvas.move(imgUFO, velX, velY)

  win.update()

  sleep(0.003)

  

win.mainloop()

Friday, July 22, 2022

Python tkinter multiple animations (BroCode)

# https://youtu.be/qK8Pfll5ha8


from tkinter import *

from time import sleep


class Ball:

  def __init__(self, canvas, x, y, dia, xVel, yVel, color, outline):

    self.canvas = canvas

    self.image = canvas.create_oval(x, y, dia, dia, fill=color, outline=outline)

    self.xVel = xVel

    self.yVel = yVel


  def move(self):

    coordinates = self.canvas.coords(self.image)

    if (coordinates[2] >= (self.canvas.winfo_width()) or coordinates[0] < 0):

      self.xVel = -self.xVel

    if (coordinates[3] >= (self.canvas.winfo_height()) or coordinates[1] < 0):

      self.yVel = -self.yVel      

    self.canvas.move(self.image, self.xVel, self.yVel)


win = Tk()

win.geometry("500x500")


WIDTH, HEIGHT = 500, 500

canvas = Canvas(win, width=WIDTH, height=HEIGHT)

canvas.place(x=0, y=0)


volley_ball = Ball(canvas, 0, 0, 100, 1, 1, "black", "black")

tennis_ball = Ball(canvas, 0, 0,  50, 4, 3, "yellow", "white")

basket_ball = Ball(canvas, 0, 0, 125, 4, 3, "orange", "white")


while True:

  volley_ball.move()

  tennis_ball.move()

  basket_ball.move()

  win.update()

  sleep(0.01)

  

win.mainloop()


Saturday, July 9, 2022

Hardware Information Tool in Python (NeuralNine)

# https://youtu.be/_9ThkldEg0c

# pip install psutil

# pip install py-cpuinfo

# pip install wmi


import platform, psutil, cpuinfo, wmi


print(f"Architecture: {platform.architecture()}")

print(f"Network Name: {platform.node()}")

print(f"Operating Sys: {platform.platform()}")


print(f"Processor: {platform.processor()}")

my_cpuinfo = cpuinfo.get_cpu_info()

#print(my_cpuinfo.keys())

print(f"Full CPU Name: {my_cpuinfo['brand_raw']}")

print(f"Advertized CPU Name: {my_cpuinfo['hz_advertised_friendly']}")

print(f"Actual CPU Name: {my_cpuinfo['hz_actual_friendly']}")


print(f"RAM:{psutil.virtual_memory().total / (1024 ** 3): .2f} GB")