Compare commits
	
		
			5 Commits
		
	
	
		
			721f2939e2
			...
			c994e2b501
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| c994e2b501 | |||
| 04433130e1 | |||
| 30844e3bae | |||
| fb79384114 | |||
| 96473af16b | 
							
								
								
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| 
						 | 
				
			
			@ -5,3 +5,5 @@ desktop.ini
 | 
			
		|||
dist/
 | 
			
		||||
build/
 | 
			
		||||
test_*
 | 
			
		||||
apiconfig.py
 | 
			
		||||
LessonPlan/
 | 
			
		||||
							
								
								
									
										129
									
								
								PyGame/Picviewer/pcview.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										129
									
								
								PyGame/Picviewer/pcview.py
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,129 @@
 | 
			
		|||
# if i was to give this to my mom and she didnt have the libraries would it work?
 | 
			
		||||
# https://www.youtube.com/watch?v=Y1rUga8Y5XY
 | 
			
		||||
import ttkbootstrap as ttk
 | 
			
		||||
from ttkbootstrap.constants import * # this imoports all ok to use?
 | 
			
		||||
from tkinter import filedialog
 | 
			
		||||
from tkinter import messagebox
 | 
			
		||||
from PIL import ImageTk, Image
 | 
			
		||||
import os, os.path
 | 
			
		||||
 | 
			
		||||
WIN_WIDTH = 1200
 | 
			
		||||
WIN_HEIGHT = 1000
 | 
			
		||||
win = ttk.Window()
 | 
			
		||||
win.title("Image Viewer")
 | 
			
		||||
ttk.Style("superhero")
 | 
			
		||||
 | 
			
		||||
# size of the window
 | 
			
		||||
win.geometry(f"{WIN_WIDTH}x{WIN_HEIGHT}")
 | 
			
		||||
 | 
			
		||||
main_frame = ttk.Frame(win)
 | 
			
		||||
main_frame.pack()
 | 
			
		||||
 | 
			
		||||
# Variable NEED TO GO OVER THIS 
 | 
			
		||||
file_location = ""
 | 
			
		||||
img_no = 0
 | 
			
		||||
imgs = []
 | 
			
		||||
 | 
			
		||||
# functions the guy put it around line 47 in the vid order?
 | 
			
		||||
 | 
			
		||||
# Picking the image folder
 | 
			
		||||
 | 
			
		||||
def explor_file():
 | 
			
		||||
    global file_location
 | 
			
		||||
    no_label.configure(text="")
 | 
			
		||||
    file_location = filedialog.askdirectory(initialdir= '/', title="Select Folder")
 | 
			
		||||
    explorer_entery.delete(0, END)
 | 
			
		||||
    explorer_entery.insert(0, file_location)
 | 
			
		||||
    set_img_list()
 | 
			
		||||
 | 
			
		||||
# extracting all the images in the folder
 | 
			
		||||
# RESIZING the images and saving them to a list 
 | 
			
		||||
def set_img_list():
 | 
			
		||||
    global imgs
 | 
			
		||||
    global file_location
 | 
			
		||||
    global img_no
 | 
			
		||||
    global image_label
 | 
			
		||||
    valid_images = [ ".jpg", ".gif", ".png,", ".tga"]
 | 
			
		||||
    imgs = []
 | 
			
		||||
    img_no =0
 | 
			
		||||
    for file in os.listdir(file_location):
 | 
			
		||||
        ext = os.path.splitext(file)[1]
 | 
			
		||||
        if ext.lower() not in valid_images:
 | 
			
		||||
            continue
 | 
			
		||||
        img = Image.open(os.path.join(file_location, file))
 | 
			
		||||
 | 
			
		||||
        # RESIZE the images
 | 
			
		||||
        w, h = img.size # Getting the current size (width and height) of the image
 | 
			
		||||
        n_height = 800 #setting the new height that is a constant
 | 
			
		||||
        n_width = int((n_height/h) * w) # calculating the new width
 | 
			
		||||
        img = img.resize((n_width, n_height))
 | 
			
		||||
        imgs.append(ImageTk.PhotoImage(img))
 | 
			
		||||
    
 | 
			
		||||
    if len(imgs) >= 1:
 | 
			
		||||
        image_label.configure(image=imgs[img_no])
 | 
			
		||||
        no_label.configure(text=f"{img_no+1}/{len(imgs)}")
 | 
			
		||||
    else:
 | 
			
		||||
        messagebox.showerror("No image", "No image in this directory, choose another to view images") 
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# Moving to the next image
 | 
			
		||||
def next_img():
 | 
			
		||||
    global img_no
 | 
			
		||||
    global imgs
 | 
			
		||||
    no_of_img = len(imgs)
 | 
			
		||||
    if img_no < no_of_img-1:
 | 
			
		||||
        img_no+=1
 | 
			
		||||
        image_label.configure(image=imgs[img_no])
 | 
			
		||||
 | 
			
		||||
    no_label.configure(text=f"{img_no+1}/{no_of_img}")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# previous image button
 | 
			
		||||
def prev_img():
 | 
			
		||||
    global img_no
 | 
			
		||||
    global imgs
 | 
			
		||||
    if img_no > 0:
 | 
			
		||||
        img_no-=1
 | 
			
		||||
        image_label.configure(image=imgs[img_no])
 | 
			
		||||
    no_label.configure(text=f"{img_no+1}/{len(imgs)}")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
explorer_frame = ttk.Frame(main_frame)
 | 
			
		||||
explorer_frame.grid(row=0, column=0, padx=10, pady=(10, 0))
 | 
			
		||||
 | 
			
		||||
explorer_entery = ttk.Entry(explorer_frame, width=80)
 | 
			
		||||
explorer_entery.grid(row=0, column=0, columnspan=2, padx=(80, 0) )
 | 
			
		||||
 | 
			
		||||
image_frame = ttk.Frame(main_frame)
 | 
			
		||||
image_frame.grid(row=1,column=0)
 | 
			
		||||
 | 
			
		||||
btn_frame = ttk.Frame(main_frame)
 | 
			
		||||
btn_frame.grid(row=2,column=0)
 | 
			
		||||
 | 
			
		||||
no_label = ttk.Label(image_frame, font=("Arial" , 20, "bold"))
 | 
			
		||||
no_label.grid(row=0, column=4, pady=(10,0), sticky=NW)
 | 
			
		||||
 | 
			
		||||
image_label = ttk.Label(image_frame, width=100, text="")
 | 
			
		||||
image_label.grid(row=1, column=0, padx=(60, 0), pady=10, rowspan=10, columnspan=8)
 | 
			
		||||
 | 
			
		||||
prev_btn = ttk.Button(btn_frame, text="Previous", command=prev_img)
 | 
			
		||||
prev_btn.grid(row=0, column=0, padx=10)
 | 
			
		||||
 | 
			
		||||
next_btn = ttk.Button(btn_frame, text="  Next  ", command=next_img)
 | 
			
		||||
next_btn.grid(row=0, column=1, padx=10)
 | 
			
		||||
 | 
			
		||||
explorer_btn = ttk.Button(explorer_frame, text="Choose Location", command=explor_file)
 | 
			
		||||
explorer_btn.grid(row=0, column=5, padx=10)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
win.mainloop()
 | 
			
		||||
| 
						 | 
				
			
			@ -1,13 +1,19 @@
 | 
			
		|||
import os
 | 
			
		||||
os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = "hide"
 | 
			
		||||
import pygame
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
pygame.init()
 | 
			
		||||
 | 
			
		||||
SCREEN_WIDTH = 800
 | 
			
		||||
SCREEN_HEIGTH = 600
 | 
			
		||||
FPS = 60
 | 
			
		||||
STEP_SIZE = 4
 | 
			
		||||
 | 
			
		||||
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGTH))
 | 
			
		||||
player = pygame.Rect((300,250,50,50))
 | 
			
		||||
 | 
			
		||||
clock = pygame.time.Clock()
 | 
			
		||||
run = True
 | 
			
		||||
while run:
 | 
			
		||||
    screen.fill((0, 0, 0))
 | 
			
		||||
| 
						 | 
				
			
			@ -15,18 +21,20 @@ while run:
 | 
			
		|||
 | 
			
		||||
    key = pygame.key.get_pressed()
 | 
			
		||||
    if key[pygame.K_a] == True:
 | 
			
		||||
        player.move_ip(-1, 0)
 | 
			
		||||
        player.move_ip((-1 * STEP_SIZE), 0)
 | 
			
		||||
    elif key[pygame.K_d] == True:
 | 
			
		||||
        player.move_ip(1, 0)
 | 
			
		||||
        player.move_ip((1 * STEP_SIZE), 0)
 | 
			
		||||
    elif key[pygame.K_w] == True:
 | 
			
		||||
        player.move_ip(0, -1)
 | 
			
		||||
        player.move_ip(0, (-1 * STEP_SIZE))
 | 
			
		||||
    elif key[pygame.K_s] == True:
 | 
			
		||||
        player.move_ip(0, 1)
 | 
			
		||||
        player.move_ip(0, (1 * STEP_SIZE))
 | 
			
		||||
 | 
			
		||||
    for event in pygame.event.get():
 | 
			
		||||
        if event.type == pygame.QUIT:
 | 
			
		||||
            run = False
 | 
			
		||||
 | 
			
		||||
    pygame.display.update()
 | 
			
		||||
    clock.tick(FPS)
 | 
			
		||||
 | 
			
		||||
    
 | 
			
		||||
pygame.quit()
 | 
			
		||||
							
								
								
									
										93
									
								
								PyGame/practice/gameprac/smup.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										93
									
								
								PyGame/practice/gameprac/smup.py
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,93 @@
 | 
			
		|||
import os
 | 
			
		||||
os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = "hide"
 | 
			
		||||
import pygame
 | 
			
		||||
import random
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
WIDTH = 480
 | 
			
		||||
HEIGHT = 600
 | 
			
		||||
WINDOW_SIZE = (WIDTH, HEIGHT)
 | 
			
		||||
FPS = 60
 | 
			
		||||
 | 
			
		||||
WHITE = (255, 255, 255)
 | 
			
		||||
BLACK = (0, 0, 0)
 | 
			
		||||
RED = (255, 0, 0)
 | 
			
		||||
GREEN = (0, 255, 0)
 | 
			
		||||
BLUE = (0, 0, 255)
 | 
			
		||||
 | 
			
		||||
pygame.init()
 | 
			
		||||
pygame.mixer.init()
 | 
			
		||||
screen = pygame.display.set_mode(WINDOW_SIZE)
 | 
			
		||||
pygame.display.set_caption("Shmup")
 | 
			
		||||
clock = pygame.time.Clock()
 | 
			
		||||
 | 
			
		||||
all_sprites = pygame.sprite.Group()
 | 
			
		||||
 | 
			
		||||
class PLayer(pygame.sprite.Sprite):
 | 
			
		||||
    def __init__(self):
 | 
			
		||||
        pygame.sprite.Sprite.__init__(self)
 | 
			
		||||
        self.image = pygame.Surface((50, 40))
 | 
			
		||||
        self.image.fill(GREEN)
 | 
			
		||||
        self.rect = self.image.get_rect()
 | 
			
		||||
        self.rect.centerx =WIDTH / 2
 | 
			
		||||
        self.rect.bottom = HEIGHT - 10
 | 
			
		||||
        self.speedx = 0
 | 
			
		||||
 | 
			
		||||
    def update(self):
 | 
			
		||||
        self.speedx = 0
 | 
			
		||||
        keystate = pygame.key.get_pressed()
 | 
			
		||||
        if keystate[pygame.K_a]:
 | 
			
		||||
            self.speedx = -8
 | 
			
		||||
        if keystate[pygame.K_d]:
 | 
			
		||||
            self.speedx = 8
 | 
			
		||||
        self.rect.x += self.speedx
 | 
			
		||||
        if self.rect.right > WIDTH:
 | 
			
		||||
            self.rect.right = WIDTH
 | 
			
		||||
        if self.rect.left < 0:
 | 
			
		||||
            self.rect.left = 0
 | 
			
		||||
 | 
			
		||||
class Mob(pygame.sprite.Sprite):
 | 
			
		||||
    def __init__(self):
 | 
			
		||||
        pygame.sprite.Sprite.__init__(self)
 | 
			
		||||
        self.image = pygame.Surface((30, 40))
 | 
			
		||||
        self.image.fill(RED)
 | 
			
		||||
        self.rect = self.image.get_rect()
 | 
			
		||||
        self.rect.x = random.randrange(0, WIDTH - self.rect.width)
 | 
			
		||||
        self.rect.y = random.randrange(-100, -40)
 | 
			
		||||
        self.speedy = random.randrange(1, 8)
 | 
			
		||||
        self.speedx = random.randrange(-3, 3)
 | 
			
		||||
 | 
			
		||||
    
 | 
			
		||||
    def update(self):
 | 
			
		||||
        self.rect.y += self.speedy
 | 
			
		||||
        self.rect.x += self.speedx
 | 
			
		||||
        if self.rect.top > HEIGHT + 10:
 | 
			
		||||
            self.rect.x = random.randrange(0, WIDTH - self.rect.width)
 | 
			
		||||
            self.rect.y = random.randrange(-100, -40)
 | 
			
		||||
            self.speed = random.randrange(1, 8)
 | 
			
		||||
 | 
			
		||||
all_sprites = pygame.sprite.Group()
 | 
			
		||||
mobs = pygame.sprite.Group()
 | 
			
		||||
player = PLayer()
 | 
			
		||||
all_sprites.add(player)
 | 
			
		||||
for i in range(8):
 | 
			
		||||
    m = Mob()
 | 
			
		||||
    all_sprites.add(m)
 | 
			
		||||
    mobs.add(m)
 | 
			
		||||
 | 
			
		||||
running = True
 | 
			
		||||
while running:
 | 
			
		||||
    clock.tick(FPS)
 | 
			
		||||
    for event in pygame.event.get():
 | 
			
		||||
        if event.type == pygame.QUIT:
 | 
			
		||||
            running = False
 | 
			
		||||
 | 
			
		||||
    all_sprites.update()
 | 
			
		||||
 | 
			
		||||
    screen.fill(BLACK)
 | 
			
		||||
    all_sprites.draw(screen)
 | 
			
		||||
    pygame.display.flip()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
pygame.quit()
 | 
			
		||||
| 
						 | 
				
			
			@ -1,6 +1,6 @@
 | 
			
		|||
import pygame
 | 
			
		||||
import random
 | 
			
		||||
import os
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
WIDTH = 360
 | 
			
		||||
| 
						 | 
				
			
			@ -19,7 +19,6 @@ pygame.mixer.init()
 | 
			
		|||
screen = pygame.display.set_mode(WINDOW_SIZE)
 | 
			
		||||
pygame.display.set_caption("My Game")
 | 
			
		||||
clock = pygame.time.Clock()
 | 
			
		||||
os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = "hide"
 | 
			
		||||
running = True
 | 
			
		||||
while running:
 | 
			
		||||
    clock.tick(FPS)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										105
									
								
								PyGame/practice/storage/pcview.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										105
									
								
								PyGame/practice/storage/pcview.py
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,105 @@
 | 
			
		|||
 | 
			
		||||
# https://www.youtube.com/watch?v=Y1rUga8Y5XY
 | 
			
		||||
import ttkbootstrap as ttk
 | 
			
		||||
from ttkbootstrap.constants import * # this imoports all ok to use?
 | 
			
		||||
from tkinter import filedialog
 | 
			
		||||
from tkinter import messagebox
 | 
			
		||||
from PIL import ImageTk, Image
 | 
			
		||||
import os, os.path
 | 
			
		||||
 | 
			
		||||
win = ttk.Window()
 | 
			
		||||
win.title("Image Viewer")
 | 
			
		||||
ttk.Style("superhero")
 | 
			
		||||
 | 
			
		||||
# size of the window
 | 
			
		||||
win.geometry("800x600")
 | 
			
		||||
 | 
			
		||||
main_frame = ttk.Frame(win)
 | 
			
		||||
main_frame.pack()
 | 
			
		||||
 | 
			
		||||
# Variable NEED TO GO OVER THIS 
 | 
			
		||||
file_location = ""
 | 
			
		||||
img_no = 0
 | 
			
		||||
imgs = []
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
explorer_frame = ttk.Frame(main_frame)
 | 
			
		||||
explorer_frame.grid(row=0, column=0, padx=10, pady=(10, 0))
 | 
			
		||||
 | 
			
		||||
explorer_entery = ttk.Entry(explorer_frame, width=80)
 | 
			
		||||
explorer_entery.grid(row=0, column=0, columnspan=2, padx=(80, 0) )
 | 
			
		||||
 | 
			
		||||
image_frame = ttk.Frame(main_frame)
 | 
			
		||||
image_frame.grid(row=1,column=0)
 | 
			
		||||
 | 
			
		||||
btn_frame = ttk.Frame(main_frame)
 | 
			
		||||
btn_frame.grid(row=2,column=0)
 | 
			
		||||
 | 
			
		||||
no_label = ttk.Label(image_frame, font=("Arial" , 20, "bold"))
 | 
			
		||||
no_label.grid(row=0, column=4, pady=(10,0), sticky=NW)
 | 
			
		||||
 | 
			
		||||
image_label = ttk.Label(image_frame, width=100, text="")
 | 
			
		||||
image_label.grid(row=1, column=0, padx=(60, 0), pady=10, rowspan=10, columnspan=8)
 | 
			
		||||
 | 
			
		||||
# functions the guy put it around line 47 in the vid order?
 | 
			
		||||
 | 
			
		||||
# Picking the image folder
 | 
			
		||||
 | 
			
		||||
def explor_file():
 | 
			
		||||
    global file_location
 | 
			
		||||
    file_location = filedialog.askdirectory(initialdir= '/', title="Selevt Folder")
 | 
			
		||||
    explorer_entery.delete(0, END)
 | 
			
		||||
    explorer_entery.insert(0, file_location)
 | 
			
		||||
    set_img_list()
 | 
			
		||||
 | 
			
		||||
# extracting all the images in the folder
 | 
			
		||||
# RESIZING the images and saving them to a list 
 | 
			
		||||
def set_img_list():
 | 
			
		||||
    global imgs
 | 
			
		||||
    global file_location
 | 
			
		||||
    global img_no
 | 
			
		||||
    global image_label
 | 
			
		||||
    valid_images = [ ".jpg", ".gif", ".png,", ".tga"]
 | 
			
		||||
    imgs = []
 | 
			
		||||
    img_no =0
 | 
			
		||||
    for file in os.listdir(file_location):
 | 
			
		||||
        ext = os.path.splitext(file)[1]
 | 
			
		||||
        if ext.lower() not in valid_images:
 | 
			
		||||
            continue
 | 
			
		||||
        img = Image.open(os.path.join(file_location, file))
 | 
			
		||||
 | 
			
		||||
        # RESIZE the images
 | 
			
		||||
        w, h = img.size # Getting the current size (width and height) of the image
 | 
			
		||||
        n_height = 400 #setting the new height that is a constant
 | 
			
		||||
        n_width = int((n_height/h) * w) # calculating the new width
 | 
			
		||||
        img = img.resize((n_width, n_height))
 | 
			
		||||
        imgs.append(ImageTk.PhotoImage(img))
 | 
			
		||||
    
 | 
			
		||||
    if len(imgs) >= 1:
 | 
			
		||||
        image_label.configure(image=imgs[img_no])
 | 
			
		||||
        no_label.configure(text=f"{img_no+1}/{len(imgs)}")
 | 
			
		||||
    else:
 | 
			
		||||
        messagebox.showerror("No image", "No image in this directory, choose another to view images") 
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
prev_btn = ttk.Button(btn_frame, text="Previous")
 | 
			
		||||
prev_btn.grid(row=0, column=0, padx=10)
 | 
			
		||||
 | 
			
		||||
next_btn = ttk.Button(btn_frame, text="  Next  ")
 | 
			
		||||
next_btn.grid(row=0, column=1, padx=10)
 | 
			
		||||
 | 
			
		||||
explorer_btn = ttk.Button(explorer_frame, text="Choose Location", command=explor_file)
 | 
			
		||||
explorer_btn.grid(row=0, column=5, padx=10)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
win.mainloop()
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user