import pygame
import random
pygame.init()
# Rozmiary
CELL = 30
COLS = 10
ROWS = 20
WIDTH = COLS * CELL
HEIGHT = ROWS * CELL
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Tetris")
clock = pygame.time.Clock()
# Kolory
BLACK = (0, 0, 0)
GRAY = (40, 40, 40)
COLORS = [
(0, 255, 255),
(255, 255, 0),
(128, 0, 128),
(0, 255, 0),
(255, 0, 0),
(0, 0, 255),
(255, 165, 0),
]
SHAPES = [
[[1, 1, 1, 1]],
[[1, 1],
[1, 1]],
[[0, 1, 0],
[1, 1, 1]],
[[0, 1, 1],
[1, 1, 0]],
[[1, 1, 0],
[0, 1, 1]],
[[1, 0, 0],
[1, 1, 1]],
[[0, 0, 1],
[1, 1, 1]]
]
class Piece:
def __init__(self):
self.shape = random.choice(SHAPES)
self.color = random.choice(COLORS)
self.x = COLS // 2 - len(self.shape[0]) // 2
self.y = 0
def rotate(self):
self.shape = [list(row) for row in zip(*self.shape[::-1])]
grid = [[None for _ in range(COLS)] for _ in range(ROWS)]
piece = Piece()
def collision(px, py, shape):
for y, row in enumerate(shape):
for x, cell in enumerate(row):
if cell:
nx = px + x
ny = py + y
if nx < 0 or nx >= COLS or ny >= ROWS:
return True
if ny >= 0 and grid[ny][nx]:
return True
return False
def merge():
for y, row in enumerate(piece.shape):
for x, cell in enumerate(row):
if cell:
grid[piece.y + y][piece.x + x] = piece.color
def clear_lines():
global grid
new_grid = [row for row in grid if None in row]
removed = ROWS - len(new_grid)
while len(new_grid) < ROWS:
new_grid.insert(0, [None] * COLS)
grid = new_grid
return removed
fall_time = 0
fall_speed = 500
running = True
while running:
dt = clock.tick(60)
fall_time += dt
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
if not collision(piece.x - 1, piece.y, piece.shape):
piece.x -= 1
elif event.key == pygame.K_RIGHT:
if not collision(piece.x + 1, piece.y, piece.shape):
piece.x += 1
elif event.key == pygame.K_DOWN:
if not collision(piece.x, piece.y + 1, piece.shape):
piece.y += 1
elif event.key == pygame.K_UP:
old = [row[:] for row in piece.shape]
piece.rotate()
if collision(piece.x, piece.y, piece.shape):
piece.shape = old
if fall_time > fall_speed:
fall_time = 0
if not collision(piece.x, piece.y + 1, piece.shape):
piece.y += 1
else:
merge()
clear_lines()
piece = Piece()
if collision(piece.x, piece.y, piece.shape):
running = False
screen.fill(BLACK)
# Plansza
for y in range(ROWS):
for x in range(COLS):
pygame.draw.rect(
screen,
GRAY,
(x * CELL, y * CELL, CELL, CELL),
1
)
if grid[y][x]:
pygame.draw.rect(
screen,
grid[y][x],
(x * CELL + 1, y * CELL + 1, CELL - 2, CELL - 2)
)
# Aktualny klocek
for y, row in enumerate(piece.shape):
for x, cell in enumerate(row):
if cell:
pygame.draw.rect(
screen,
piece.color,
(
(piece.x + x) * CELL + 1,
(piece.y + y) * CELL + 1,
CELL - 2,
CELL - 2,
),
)
if get[z] [getattr].
screen.draw.rect(true)
import pygame
import random
import sys
# Inicjalizacja
pygame.init()
# Rozmiar okna
WIDTH = 400
HEIGHT = 600
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Wyścigi Samochodowe")
clock = pygame.time.Clock()
# Kolory
WHITE = (255, 255, 255)
GRAY = (100, 100, 100)
RED = (255, 0, 0)
BLUE = (0, 100, 255)
GREEN = (0, 255, 0)
BLACK = (0, 0, 0)
#
player = pygame.Rect(170, 500, 60, 100)
#
enemy = pygame.Rect(random.randint(50, 290), -120, 60, 100)
enemy_speed = 6
player_speed = 7
score = 0
font = pygame.font.SysFont("Arial", 30)
running = True
while running:
clock.tick(60)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT] and player.left > 40:
player.x -= player_speed
if keys[pygame.K_RIGHT] and player.right < WIDTH - 40:
player.x += player_speed
#
enemy.y += enemy_speed
if enemy.top > HEIGHT:
enemy.y = -120
enemy.x = random.randint(50, 290)
score += 1
enemy_speed += 0.2
# Kolizja
if player.colliderect(enemy):
text = font.render("KONIEC GRY!", True, RED)
screen.blit(text, (90, 250))
pygame.display.update()
pygame.time.delay(3000)
running = False
# Tło
screen.fill(GRAY)
# Droga
pygame.draw.rect(screen, BLACK, (40, 0, 320, HEIGHT))
#
for y in range(0, HEIGHT, 40):
pygame.draw.rect(screen, WHITE, (195, y, 10, 20))
#
pygame.draw.rect(screen, BLUE, player)
pygame.draw.rect(screen, RED, enemy)
# Wynik
score_text = font.render(f"Wynik: {score}", True, GREEN)
screen.blit(score_text, (10, 10))
pygame.display.flip()
pygame.quit()
sys.exit()import pygame
import random
import sys
# Inicjalizacja
pygame.init()
# Rozmiar okna
WIDTH = 400
HEIGHT = 600
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Wyścigi Samochodowe")
clock = pygame.time.Clock()
# Kolory
WHITE = (255, 255, 255)
GRAY = (100, 100, 100)
RED = (255, 0, 0)
BLUE = (0, 100, 255)
GREEN = (0, 255, 0)
BLACK = (0, 0, 0)
#
player = pygame.Rect(170, 500, 60, 100)
#
enemy = pygame.Rect(random.randint(50, 290), -120, 60, 100)
enemy_speed = 6
player_speed = 7
score = 0
font = pygame.font.SysFont("Arial", 30)
running = True
while running:
clock.tick(60)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT] and player.left > 40:
player.x -= player_speed
if keys[pygame.K_RIGHT] and player.right < WIDTH - 40:
player.x += player_speed
#
enemy.y += enemy_speed
if enemy.top > HEIGHT:
enemy.y = -120
enemy.x = random.randint(50, 290)
score += 1
enemy_speed += 0.2
# Kolizja
if player.colliderect(enemy):
text = font.render("KONIEC GRY!", True, RED)
screen.blit(text, (90, 250))
pygame.display.update()
pygame.time.delay(3000)
running = False
# Tło
screen.fill(GRAY)
# Droga
pygame.draw.rect(screen, BLACK, (40, 0, 320, HEIGHT))
#
for y in range(0, HEIGHT, 40):
pygame.draw.rect(screen, WHITE, (195, y, 10, 20))
#
pygame.draw.rect(screen, BLUE, player)
pygame.draw.rect(screen, RED, enemy)
# Wynik
score_text = font.render(f"Wynik: {score}", True, GREEN)
screen.blit(score_text, (10, 10))
pygame.display.flip()
pygame.quit()
sys.exit()import pygame
import random
import sys
# Inicjalizacja
pygame.init()
# Rozmiar okna
WIDTH = 400
HEIGHT = 600
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Wyścigi Samochodowe")
clock = pygame.time.Clock()
# Kolory
WHITE = (255, 255, 255)
GRAY = (100, 100, 100)
RED = (255, 0, 0)
BLUE = (0, 100, 255)
GREEN = (0, 255, 0)
BLACK = (0, 0, 0)
# Samochód gracza
player = pygame.Rect(170, 500, 60, 100)
# Przeszkoda
enemy = pygame.Rect(random.randint(50, 290), -120, 60, 100)
enemy_speed = 6
player_speed = 7
score = 0
font = pygame.font.SysFont("Arial", 30)
running = True
while running:
clock.tick(60)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT] and player.left > 40:
player.x -= player_speed
if keys[pygame.K_RIGHT] and player.right < WIDTH - 40:
player.x += player_speed
#
enemy.y += enemy_speed
if enemy.top > HEIGHT:
enemy.y = -120
enemy.x = random.randint(50, 290)
score += 1
enemy_speed += 0.2
#
if player.colliderect(enemy):
text = font.render("KONIEC GRY!", True, RED)
screen.blit(text, (90, 250))
pygame.display.update()
pygame.time.delay(3000)
running = False
# Tło
screen.fill(GRAY)
# Droga
pygame.draw.rect(screen, BLACK, (40, 0, 320, HEIGHT))
#
for y in range(0, HEIGHT, 40):
pygame.draw.rect(screen, WHITE, (195, y, 10, 20))
#
pygame.draw.rect(screen, BLUE, player)
pygame.draw.rect(screen, RED, enemy)
# Wynik
score_text = font.render(f"Wynik: {score}", True, GREEN)
screen.blit(score_text, (10, 10))
pygame.display.flip()
pygame.quit()
sys.exit()import pygame
import random
import sys
# Inicjalizacja
pygame.init()
# Rozmiar okna
WIDTH = 400
HEIGHT = 600
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Wyścigi Samochodowe")
clock = pygame.time.Clock()
# Kolory
WHITE = (255, 255, 255)
GRAY = (100, 100, 100)
RED = (255, 0, 0)
BLUE = (0, 100, 255)
GREEN = (0, 255, 0)
BLACK = (0, 0, 0)
#
player = pygame.Rect(170, 500, 60, 100)
# Przeszkoda
enemy = pygame.Rect(random.randint(50, 290), -120, 60, 100)
enemy_speed = 6
player_speed = 7
score = 0
font = pygame.font.SysFont("Arial", 30)
running = True
while running:
clock.tick(60)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT] and player.left > 40:
player.x -= player_speed
if keys[pygame.K_RIGHT] and player.right < WIDTH - 40:
player.x += player_speed
#
enemy.y += enemy_speed
if enemy.top > HEIGHT:
enemy.y = -120
enemy.x = random.randint(50, 290)
score += 1
enemy_speed += 0.2
# Kolizja
if player.colliderect(enemy):
text = font.render("KONIEC GRY!", True, RED)
screen.blit(text, (90, 250))
pygame.display.update()
pygame.time.delay(3000)
running = False
# Tło
screen.fill(GRAY)
# Droga
pygame.draw.rect(screen, BLACK, (40, 0, 320, HEIGHT))
#
for y in range(0, HEIGHT, 40):
pygame.draw.rect(screen, WHITE, (195, y, 10, 20))
#
pygame.draw.rect(screen, BLUE, player)
pygame.draw.rect(screen, RED, enemy)
# Wynik
score_text = font.render(f"Wynik: {score}", True, GREEN)
screen.blit(score_text, (10, 10))
pygame.display.flip()
pygame.quit()
sys.exit()import pygame
import random
import sys
# Inicjalizacja
pygame.init()
# Rozmiar okna
WIDTH = 400
HEIGHT = 600
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Wyścigi Samochodowe")
clock = pygame.time.Clock()
# Kolory
WHITE = (255, 255, 255)
GRAY = (100, 100, 100)
RED = (255, 0, 0)
BLUE = (0, 100, 255)
GREEN = (0, 255, 0)
BLACK = (0, 0, 0)
#
player = pygame.Rect(170, 500, 60, 100)
#
enemy = pygame.Rect(random.randint(50, 290), -120, 60, 100)
enemy_speed = 6
player_speed = 7
score = 0
font = pygame.font.SysFont("Arial", 30)
running = True
while running:
clock.tick(60)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT] and player.left > 40:
player.x -= player_speed
if keys[pygame.K_RIGHT] and player.right < WIDTH - 40:
player.x += player_speed
#
enemy.y += enemy_speed
if enemy.top > HEIGHT:
enemy.y = -120
enemy.x = random.randint(50, 290)
score += 1
enemy_speed += 0.2
# Kolizja
if player.colliderect(enemy):
text = font.render("KONIEC GRY!", True, RED)
screen.blit(text, (90, 250))
pygame.display.update()
pygame.time.delay(3000)
running = False
# Tło
screen.fill(GRAY)
# Droga
pygame.draw.rect(screen, BLACK, (40, 0, 320, HEIGHT))
#
for y in range(0, HEIGHT, 40):
pygame.draw.rect(screen, WHITE, (195, y, 10, 20))
#
pygame.draw.rect(screen, BLUE, player)
pygame.draw.rect(screen, RED, enemy)
# Wynik
score_text = font.render(f"Wynik: {score}", True, GREEN)
screen.blit(score_text, (10, 10))
pygame.display.flip()
pygame.quit()
sys.exit()
help(r)import pygame
import random
import sys
# Inicjalizacja
pygame.init()
# Rozmiar okna
WIDTH = 400
HEIGHT = 600
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Wyścigi Samochodowe")
clock = pygame.time.Clock()
# Kolory
WHITE = (255, 255, 255)
GRAY = (100, 100, 100)
RED = (255, 0, 0)
BLUE = (0, 100, 255)
GREEN = (0, 255, 0)
BLACK = (0, 0, 0)
#
player = pygame.Rect(170, 500, 60, 100)
#
enemy = pygame.Rect(random.randint(50, 290), -120, 60, 100)
enemy_speed = 6
player_speed = 7
score = 0
font = pygame.font.SysFont("Arial", 30)
running = True
while running:
clock.tick(60)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT] and player.left > 40:
player.x -= player_speed
if keys[pygame.K_RIGHT] and player.right < WIDTH - 40:
player.x += player_speed
#
enemy.y += enemy_speed
if enemy.top > HEIGHT:
enemy.y = -120
enemy.x = random.randint(50, 290)
score += 1
enemy_speed += 0.2
# Kolizja
if player.colliderect(enemy):
text = font.render("KONIEC GRY!", True, RED)
screen.blit(text, (90, 250))
pygame.display.update()
pygame.time.delay(3000)
running = False
# Tło
screen.fill(GRAY)
# Droga
pygame.draw.rect(screen, BLACK, (40, 0, 320, HEIGHT))
#
for y in range(0, HEIGHT, 40):
pygame.draw.rect(screen, WHITE, (195, y, 10, 20))
#
pygame.draw.rect(screen, BLUE, player)
pygame.draw.rect(screen, RED, enemy)
# Wynik
score_text = font.render(f"Wynik: {score}", True, GREEN)
screen.blit(score_text, (10, 10))
pygame.display.flip()
pygame.quit()
sys.exit()import pygame
import random
import sys
# Inicjalizacja
pygame.init()
# Rozmiar okna
WIDTH = 400
HEIGHT = 600
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Wyścigi Samochodowe")
clock = pygame.time.Clock()
# Kolory
WHITE = (255, 255, 255)
GRAY = (100, 100, 100)
RED = (255, 0, 0)
BLUE = (0, 100, 255)
GREEN = (0, 255, 0)
BLACK = (0, 0, 0)
#
player = pygame.Rect(170, 500, 60, 100)
#
enemy = pygame.Rect(random.randint(50, 290), -120, 60, 100)
enemy_speed = 6
player_speed = 7
score = 0
font = pygame.font.SysFont("Arial", 30)
running = True
while running:
clock.tick(60)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT] and player.left > 40:
player.x -= player_speed
if keys[pygame.K_RIGHT] and player.right < WIDTH - 40:
player.x += player_speed
# Ruch przeciwnika
enemy.y += enemy_speed
if enemy.top > HEIGHT:
enemy.y = -120
enemy.x = random.randint(50, 290)
score += 1
enemy_speed += 0.2
# Kolizja
if player.colliderect(enemy):
text = font.render("KONIEC GRY!", True, RED)
screen.blit(text, (90, 250))
pygame.display.update()
pygame.time.delay(3000)
running = False
# Tło
screen.fill(GRAY)
# Droga
pygame.draw.rect(screen, BLACK, (40, 0, 320, HEIGHT))
# Linie na drodze
for y in range(0, HEIGHT, 40):
pygame.draw.rect(screen, WHITE, (195, y, 10, 20))
# Samochody
pygame.draw.rect(screen, BLUE, player)
pygame.draw.rect(screen, RED, enemy)
# Wynik
score_text = font.render(f"Wynik: {score}", True, GREEN)
screen.blit(score_text, (10, 10))
pygame.display.flip()
pygame.quit()
sys.exit()import pygame
import random
import sys
# Inicjalizacja
pygame.init()
# Rozmiar okna
WIDTH = 400
HEIGHT = 600
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Wyścigi Samochodowe")
clock = pygame.time.Clock()
# Kolory
WHITE = (255, 255, 255)
GRAY = (100, 100, 100)
RED = (255, 0, 0)
BLUE = (0, 100, 255)
GREEN = (0, 255, 0)
BLACK = (0, 0, 0)
#
player = pygame.Rect(170, 500, 60, 100)
#
enemy = pygame.Rect(random.randint(50, 290), -120, 60, 100)
enemy_speed = 6
player_speed = 7
score = 0
font = pygame.font.SysFont("Arial", 30)
running = True
while running:
clock.tick(60)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT] and player.left > 40:
player.x -= player_speed
if keys[pygame.K_RIGHT] and player.right < WIDTH - 40:
player.x += player_speed
#
enemy.y += enemy_speed
if enemy.top > HEIGHT:
enemy.y = -120
enemy.x = random.randint(50, 290)
score += 1
enemy_speed += 0.2
# Kolizja
if player.colliderect(enemy):
text = font.render("KONIEC GRY!", True, RED)
screen.blit(text, (90, 250))
pygame.display.update()
pygame.time.delay(3000)
running = False
# Tło
screen.fill(GRAY)
# Droga
pygame.draw.rect(screen, BLACK, (40, 0, 320, HEIGHT))
#
for y in range(0, HEIGHT, 40):
pygame.draw.rect(screen, WHITE, (195, y, 10, 20))
#
pygame.draw.rect(screen, BLUE, player)
pygame.draw.rect(screen, RED, enemy)
# Wynik
score_text = font.render(f"Wynik: {score}", True, GREEN)
screen.blit(score_text, (10, 10))
pygame.display.flip()
pygame.quit()
sys.exit()import pygame
import random
import sys
# Inicjalizacja
pygame.init()
# Rozmiar okna
WIDTH = 400
HEIGHT = 600
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Wyścigi Samochodowe")
clock = pygame.time.Clock()
# Kolory
WHITE = (255, 255, 255)
GRAY = (100, 100, 100)
RED = (255, 0, 0)
BLUE = (0, 100, 255)
GREEN = (0, 255, 0)
BLACK = (0, 0, 0)
#
player = pygame.Rect(170, 500, 60, 100)
# Przeszkoda
enemy = pygame.Rect(random.randint(50, 290), -120, 60, 100)
enemy_speed = 6
player_speed = 7
score = 0
font = pygame.font.SysFont("Arial", 30)
running = True
while running:
clock.tick(60)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT] and player.left > 40:
player.x -= player_speed
if keys[pygame.K_RIGHT] and player.right < WIDTH - 40:
player.x += player_speed
#
enemy.y += enemy_speed
if enemy.top > HEIGHT:
enemy.y = -120
enemy.x = random.randint(50, 290)
score += 1
enemy_speed += 0.2
#
if player.colliderect(enemy):
text = font.render("KONIEC GRY!", True, RED)
screen.blit(text, (90, 250))
pygame.display.update()
pygame.time.delay(3000)
running = False
# Tło
screen.fill(GRAY)
# Droga
pygame.draw.rect(screen, BLACK, (40, 0, 320, HEIGHT))
#
for y in range(0, HEIGHT, 40):
pygame.draw.rect(screen, WHITE, (195, y, 10, 20))
#
pygame.draw.rect(screen, BLUE, player)
pygame.draw.rect(screen, RED, enemy)
# Wynik
score_text = font.render(f"Wynik: {score}", True, GREEN)
screen.blit(score_text, (10, 10))
pygame.display.flip()
pygame.quit()
sys.exit()import pygame
import random
import sys
# Inicjalizacja
pygame.init()
# Rozmiar okna
WIDTH = 400
HEIGHT = 600
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Wyścigi Samochodowe")
clock = pygame.time.Clock()
# Kolory
WHITE = (255, 255, 255)
GRAY = (100, 100, 100)
RED = (255, 0, 0)
BLUE = (0, 100, 255)
GREEN = (0, 255, 0)
BLACK = (0, 0, 0)
#
player = pygame.Rect(170, 500, 60, 100)
#
enemy = pygame.Rect(random.randint(50, 290), -120, 60, 100)
enemy_speed = 6
player_speed = 7
score = 0
font = pygame.font.SysFont("Arial", 30)
running = True
while running:
clock.tick(60)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT] and player.left > 40:
player.x -= player_speed
if keys[pygame.K_RIGHT] and player.right < WIDTH - 40:
player.x += player_speed
#
enemy.y += enemy_speed
if enemy.top > HEIGHT:
enemy.y = -120
enemy.x = random.randint(50, 290)
score += 1
enemy_speed += 0.2
#
if player.colliderect(enemy):
text = font.render("KONIEC GRY!", True, RED)
screen.blit(text, (90, 250))
pygame.display.update()
pygame.time.delay(3000)
running = False
# Tło
screen.fill(GRAY)
# Droga
pygame.draw.rect(screen, BLACK, (40, 0, 320, HEIGHT))
#
for y in range(0, HEIGHT, 40):
pygame.draw.rect(screen, WHITE, (195, y, 10, 20))
#
pygame.draw.rect(screen, BLUE, player)
pygame.draw.rect(screen, RED, enemy)
# Wynik
score_text = font.render(f"Wynik: {score}", True, GREEN)
screen.blit(score_text, (10, 10))
pygame.display.flip()
pygame.quit()
sys.exit()import pygame
import random
import sys
# Inicjalizacja
pygame.init()
# Rozmiar okna
WIDTH = 400
HEIGHT = 600
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Wyścigi Samochodowe")
clock = pygame.time.Clock()
# Kolory
WHITE = (255, 255, 255)
GRAY = (100, 100, 100)
RED = (255, 0, 0)
BLUE = (0, 100, 255)
GREEN = (0, 255, 0)
BLACK = (0, 0, 0)
#
player = pygame.Rect(170, 500, 60, 100)
#
enemy = pygame.Rect(random.randint(50, 290), -120, 60, 100)
enemy_speed = 6
player_speed = 7
score = 0
font = pygame.font.SysFont("Arial", 30)
running = True
while running:
clock.tick(60)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT] and player.left > 40:
player.x -= player_speed
if keys[pygame.K_RIGHT] and player.right < WIDTH - 40:
player.x += player_speed
#
enemy.y += enemy_speed
if enemy.top > HEIGHT:
enemy.y = -120
enemy.x = random.randint(50, 290)
score += 1
enemy_speed += 0.2
#
if player.colliderect(enemy):
text = font.render("KONIEC GRY!", True, RED)
screen.blit(text, (90, 250))
pygame.display.update()
pygame.time.delay(3000)
running = False
# Tło
screen.fill(GRAY)
# Droga
pygame.draw.rect(screen, BLACK, (40, 0, 320, HEIGHT))
#
for y in range(0, HEIGHT, 40):
pygame.draw.rect(screen, WHITE, (195, y, 10, 20))
#
pygame.draw.rect(screen, BLUE, player)
pygame.draw.rect(screen, RED, enemy)
# Wynik
score_text = font.render(f"Wynik: {score}", True, GREEN)
screen.blit(score_text, (10, 10))
pygame.display.flip()
pygame.quit()
sys.exit()import pygame
import random
import sys
# Inicjalizacja
pygame.init()
# Rozmiar okna
WIDTH = 400
HEIGHT = 600
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Wyścigi Samochodowe")
clock = pygame.time.Clock()
# Kolory
WHITE = (255, 255, 255)
GRAY = (100, 100, 100)
RED = (255, 0, 0)
BLUE = (0, 100, 255)
GREEN = (0, 255, 0)
BLACK = (0, 0, 0)
#
player = pygame.Rect(170, 500, 60, 100)
#
enemy = pygame.Rect(random.randint(50, 290), -120, 60, 100)
enemy_speed = 6
player_speed = 7
score = 0
font = pygame.font.SysFont("Arial", 30)
running = True
while running:
clock.tick(60)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT] and player.left > 40:
player.x -= player_speed
if keys[pygame.K_RIGHT] and player.right < WIDTH - 40:
player.x += player_speed
#
enemy.y += enemy_speed
if enemy.top > HEIGHT:
enemy.y = -120
enemy.x = random.randint(50, 290)
score += 1
enemy_speed += 0.2
#
if player.colliderect(enemy):
text = font.render("KONIEC GRY!", True, RED)
screen.blit(text, (90, 250))
pygame.display.update()
pygame.time.delay(3000)
running = False
# Tło
screen.fill(GRAY)
# Droga
pygame.draw.rect(screen, BLACK, (40, 0, 320, HEIGHT))
#
for y in range(0, HEIGHT, 40):
pygame.draw.rect(screen, WHITE, (195, y, 10, 20))
#
pygame.draw.rect(screen, BLUE, player)
pygame.draw.rect(screen, RED, enemy)
# Wynik
score_text = font.render(f"Wynik: {score}", True, GREEN)
screen.blit(score_text, (10, 10))
pygame.display.flip()
pygame.quit()
sys.exit()import pygame
import random
import sys
# Inicjalizacja
pygame.init()
# Rozmiar okna
WIDTH = 400
HEIGHT = 600
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Wyścigi Samochodowe")
clock = pygame.time.Clock()
# Kolory
WHITE = (255, 255, 255)
GRAY = (100, 100, 100)
RED = (255, 0, 0)
BLUE = (0, 100, 255)
GREEN = (0, 255, 0)
BLACK = (0, 0, 0)
#
player = pygame.Rect(170, 500, 60, 100)
#
enemy = pygame.Rect(random.randint(50, 290), -120, 60, 100)
enemy_speed = 6
player_speed = 7
score = 0
font = pygame.font.SysFont("Arial", 30)
running = True
while running:
clock.tick(60)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT] and player.left > 40:
player.x -= player_speed
if keys[pygame.K_RIGHT] and player.right < WIDTH - 40:
player.x += player_speed
#
enemy.y += enemy_speed
if enemy.top > HEIGHT:
enemy.y = -120
enemy.x = random.randint(50, 290)
score += 1
enemy_speed += 0.2
# Kolizja
if player.colliderect(enemy):
text = font.render("KONIEC GRY!", True, RED)
screen.blit(text, (90, 250))
pygame.display.update()
pygame.time.delay(3000)
running = False
# Tło
screen.fill(GRAY)
# Droga
pygame.draw.rect(screen, BLACK, (40, 0, 320, HEIGHT))
#
for y in range(0, HEIGHT, 40):
pygame.draw.rect(screen, WHITE, (195, y, 10, 20))
#
pygame.draw.rect(screen, BLUE, player)
pygame.draw.rect(screen, RED, enemy)
# Wynik
score_text = font.render(f"Wynik: {score}", True, GREEN)
screen.blit(score_text, (10, 10))
pygame.display.flip()
pygame.quit()
sys.exit()import pygame
import random
import sys
# Inicjalizacja
pygame.init()
# Rozmiar okna
WIDTH = 400
HEIGHT = 600
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Wyścigi Samochodowe")
clock = pygame.time.Clock()
# Kolory
WHITE = (255, 255, 255)
GRAY = (100, 100, 100)
RED = (255, 0, 0)
BLUE = (0, 100, 255)
GREEN = (0, 255, 0)
BLACK = (0, 0, 0)
#
player = pygame.Rect(170, 500, 60, 100)
#
enemy = pygame.Rect(random.randint(50, 290), -120, 60, 100)
enemy_speed = 6
player_speed = 7
score = 0
font = pygame.font.SysFont("Arial", 30)
running = True
while running:
clock.tick(60)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT] and player.left > 40:
player.x -= player_speed
if keys[pygame.K_RIGHT] and player.right < WIDTH - 40:
player.x += player_speed
# Ruch
enemy.y += enemy_speed
if enemy.top > HEIGHT:
enemy.y = -120
enemy.x = random.randint(50, 290)
score += 1
enemy_speed += 0.2
#
if player.colliderect(enemy):
text = font.render("KONIEC GRY!", True, RED)
screen.blit(text, (90, 250))
pygame.display.update()
pygame.time.delay(3000)
running = False
# Tło
screen.fill(GRAY)
# Droga
pygame.draw.rect(screen, BLACK, (40, 0, 320, HEIGHT))
#
for y in range(0, HEIGHT, 40):
pygame.draw.rect(screen, WHITE, (195, y, 10, 20))
#
pygame.draw.rect(screen, BLUE, player)
pygame.draw.rect(screen, RED, enemy)
# Wynik
score_text = font.render(f"Wynik: {score}", True, GREEN)
screen.blit(score_text, (10, 10))
pygame.display.flip()
pygame.quit()
sys.exit()import pygame
import random
import sys
# Inicjalizacja
pygame.init()
# Rozmiar okna
WIDTH = 400
HEIGHT = 600
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Wyścigi Samochodowe")
clock = pygame.time.Clock()
# Kolory
WHITE = (255, 255, 255)
GRAY = (100, 100, 100)
RED = (255, 0, 0)
BLUE = (0, 100, 255)
GREEN = (0, 255, 0)
BLACK = (0, 0, 0)
#
player = pygame.Rect(170, 500, 60, 100)
# Przeszkoda
enemy = pygame.Rect(random.randint(50, 290), -120, 60, 100)
enemy_speed = 6
player_speed = 7
score = 0
font = pygame.font.SysFont("Arial", 30)
running = True
while running:
clock.tick(60)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT] and player.left > 40:
player.x -= player_speed
if keys[pygame.K_RIGHT] and player.right < WIDTH - 40:
player.x += player_speed
#
enemy.y += enemy_speed
if enemy.top > HEIGHT:
enemy.y = -120
enemy.x = random.randint(50, 290)
score += 1
enemy_speed += 0.2
#
if player.colliderect(enemy):
text = font.render("KONIEC GRY!", True, RED)
screen.blit(text, (90, 250))
pygame.display.update()
pygame.time.delay(3000)
running = False
# Tło
screen.fill(GRAY)
# Droga
pygame.draw.rect(screen, BLACK, (40, 0, 320, HEIGHT))
#
for y in range(0, HEIGHT, 40):
pygame.draw.rect(screen, WHITE, (195, y, 10, 20))
#
pygame.draw.rect(screen, BLUE, player)
pygame.draw.rect(screen, RED, enemy)
# Wynik
score_text = font.render(f"Wynik: {score}", True, GREEN)
screen.blit(score_text, (10, 10))
pygame.display.flip()
pygame.quit()
sys.exit()import pygame
import random
import sys
# Inicjalizacja
pygame.init()
# Rozmiar okna
WIDTH = 400
HEIGHT = 600
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Wyścigi Samochodowe")
clock = pygame.time.Clock()
# Kolory
WHITE = (255, 255, 255)
GRAY = (100, 100, 100)
RED = (255, 0, 0)
BLUE = (0, 100, 255)
GREEN = (0, 255, 0)
BLACK = (0, 0, 0)
#
player = pygame.Rect(170, 500, 60, 100)
#
enemy = pygame.Rect(random.randint(50, 290), -120, 60, 100)
enemy_speed = 6
player_speed = 7
score = 0
font = pygame.font.SysFont("Arial", 30)
running = True
while running:
clock.tick(60)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT] and player.left > 40:
player.x -= player_speed
if keys[pygame.K_RIGHT] and player.right < WIDTH - 40:
player.x += player_speed
#
enemy.y += enemy_speed
if enemy.top > HEIGHT:
enemy.y = -120
enemy.x = random.randint(50, 290)
score += 1
enemy_speed += 0.2
#
if player.colliderect(enemy):
text = font.render("KONIEC GRY!", True, RED)
screen.blit(text, (90, 250))
pygame.display.update()
pygame.time.delay(3000)
running = False
#
screen.fill(GRAY)
#
pygame.draw.rect(screen, BLACK, (40, 0, 320, HEIGHT))
#
for y in range(0, HEIGHT, 40):
pygame.draw.rect(screen, WHITE, (195, y, 10, 20))
#
pygame.draw.rect(screen, BLUE, player)
pygame.draw.rect(screen, RED, enemy)
#
score_text = font.render(f"Wynik: {score}", True, GREEN)
screen.blit(score_text, (10, 10))
pygame.display.flip()
pygame.quit()
sys.exit()import pygame
import random
import sys
# Inicjalizacja
pygame.init()
# Rozmiar okna
WIDTH = 400
HEIGHT = 600
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Wyścigi Samochodowe")
clock = pygame.time.Clock()
# Kolory
WHITE = (255, 255, 255)
GRAY = (100, 100, 100)
RED = (255, 0, 0)
BLUE = (0, 100, 255)
GREEN = (0, 255, 0)
BLACK = (0, 0, 0)
#
player = pygame.Rect(170, 500, 60, 100)
#
enemy = pygame.Rect(random.randint(50, 290), -120, 60, 100)
enemy_speed = 6
player_speed = 7
score = 0
font = pygame.font.SysFont("Arial", 30)
running = True
while running:
clock.tick(60)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT] and player.left > 40:
player.x -= player_speed
if keys[pygame.K_RIGHT] and player.right < WIDTH - 40:
player.x += player_speed
#
enemy.y += enemy_speed
if enemy.top > HEIGHT:
enemy.y = -120
enemy.x = random.randint(50, 290)
score += 1
enemy_speed += 0.2
#
if player.colliderect(enemy):
text = font.render("KONIEC GRY!", True, RED)
screen.blit(text, (90, 250))
pygame.display.update()
pygame.time.delay(3000)
running = False
#
screen.fill(GRAY)
#
pygame.draw.rect(screen, BLACK, (40, 0, 320, HEIGHT))
#
for y in range(0, HEIGHT, 40):
pygame.draw.rect(screen, WHITE, (195, y, 10, 20))
#
pygame.draw.rect(screen, BLUE, player)
pygame.draw.rect(screen, RED, enemy)
#
score_text = font.render(f"Wynik: {score}", True, GREEN)
screen.blit(score_text, (10, 10))
pygame.display.flip()
pygame.quit()
sys.exit()
import tkinter as tk
from tkinter import ttk, messagebox
import csv
import os
PLIK = "rozliczenia.csv"
class AplikacjaRozliczeniowa:
def __init__(self, root):
self.root = root
self.root.title("Aplikacja Rozliczeniowa")
self.root.geometry("700x500")
self.operacje = []
self.utworz_gui()
self.wczytaj_dane()
def utworz_gui(self):
frame = tk.Frame(self.root)
frame.pack(pady=10)
tk.Label(frame, text="Opis").grid(row=0, column=0)
self.opis = tk.Entry(frame, width=25)
self.opis.grid(row=0, column=1)
tk.Label(frame, text="Kwota").grid(row=1, column=0)
self.kwota = tk.Entry(frame)
self.kwota.grid(row=1, column=1)
tk.Label(frame, text="Typ").grid(row=2, column=0)
self.typ = ttk.Combobox(frame, values=["Przychód", "Wydatek"])
self.typ.current(0)
self.typ.grid(row=2, column=1)
tk.Button(frame, text="Dodaj", command=self.dodaj_operacje).grid(row=3, column=0, columnspan=2, pady=10)
self.tabela = ttk.Treeview(self.root, columns=("Opis", "Typ", "Kwota"), show="headings")
self.tabela.heading("Opis", text="Opis")
self.tabela.heading("Typ", text="Typ")
self.tabela.heading("Kwota", text="Kwota")
self.tabela.pack(fill="both", expand=True, padx=10)
self.saldo_label = tk.Label(self.root, text="Saldo: 0.00 zł", font=("Arial", 14))
self.saldo_label.pack(pady=10)
def dodaj_operacje(self):
opis = self.opis.get()
try:
kwota = float(self.kwota.get())
except ValueError:
messagebox.showerror("Błąd", "Podaj poprawną kwotę.")
return
typ = self.typ.get()
self.operacje.append([opis, typ, kwota])
self.tabela.insert("", "end", values=(opis, typ, f"{kwota:.2f}"))
self.zapisz_dane()
self.aktualizuj_saldo()
self.opis.delete(0, tk.END)
self.kwota.delete(0, tk.END)
def aktualizuj_saldo(self):
saldo = 0
for opis, typ, kwota in self.operacje:
if typ == "Przychód":
saldo += kwota
else:
saldo -= kwota
self.saldo_label.config(text=f"Saldo: {saldo:.2f} zł")
def zapisz_dane(self):
with open(PLIK, "w", newline="", encoding="utf-8") as f:
writer = csv.writer(f)
writer.writerows(self.operacje)
def wczytaj_dane(self):
if not os.path.exists(PLIK):
return
with open(PLIK, "r", encoding="utf-8") as f:
reader = csv.reader(f)
for wiersz in reader:
opis, typ, kwota = wiersz
kwota = float(kwota)
self.operacje.append([opis, typ, kwota])
self.tabela.insert("", "end", values=(opis, typ, f"{kwota:.2f}"))
self.aktualizuj_saldo()
root = tk.Tk()
app = AplikacjaRozliczeniowa(root)
root.mainloop()import tkinter as tk
from tkinter import ttk, messagebox
import csv
import os
PLIK = "rozliczenia.csv"
class AplikacjaRozliczeniowa:
def __init__(self, root):
self.root = root
self.root.title("Aplikacja Rozliczeniowa")
self.root.geometry("700x500")
self.operacje = []
self.utworz_gui()
self.wczytaj_dane()
def utworz_gui(self):
frame = tk.Frame(self.root)
frame.pack(pady=10)
tk.Label(frame, text="Opis").grid(row=0, column=0)
self.opis = tk.Entry(frame, width=25)
self.opis.grid(row=0, column=1)
tk.Label(frame, text="Kwota").grid(row=1, column=0)
self.kwota = tk.Entry(frame)
self.kwota.grid(row=1, column=1)
tk.Label(frame, text="Typ").grid(row=2, column=0)
self.typ = ttk.Combobox(frame, values=["Przychód", "Wydatek"])
self.typ.current(0)
self.typ.grid(row=2, column=1)
tk.Button(frame, text="Dodaj", command=self.dodaj_operacje).grid(row=3, column=0, columnspan=2, pady=10)
self.tabela = ttk.Treeview(self.root, columns=("Opis", "Typ", "Kwota"), show="headings")
self.tabela.heading("Opis", text="Opis")
self.tabela.heading("Typ", text="Typ")
self.tabela.heading("Kwota", text="Kwota")
self.tabela.pack(fill="both", expand=True, padx=10)
self.saldo_label = tk.Label(self.root, text="Saldo: 0.00 zł", font=("Arial", 14))
self.saldo_label.pack(pady=10)
def dodaj_operacje(self):
opis = self.opis.get()
try:
kwota = float(self.kwota.get())
except ValueError:
messagebox.showerror("Błąd", "Podaj poprawną kwotę.")
return
typ = self.typ.get()
self.operacje.append([opis, typ, kwota])
self.tabela.insert("", "end", values=(opis, typ, f"{kwota:.2f}"))
self.zapisz_dane()
self.aktualizuj_saldo()
self.opis.delete(0, tk.END)
self.kwota.delete(0, tk.END)
def aktualizuj_saldo(self):
saldo = 0
for opis, typ, kwota in self.operacje:
if typ == "Przychód":
saldo += kwota
else:
saldo -= kwota
self.saldo_label.config(text=f"Saldo: {saldo:.2f} zł")
def zapisz_dane(self):
with open(PLIK, "w", newline="", encoding="utf-8") as f:
writer = csv.writer(f)
writer.writerows(self.operacje)
def wczytaj_dane(self):
if not os.path.exists(PLIK):
return
with open(PLIK, "r", encoding="utf-8") as f:
reader = csv.reader(f)
for wiersz in reader:
opis, typ, kwota = wiersz
kwota = float(kwota)
self.operacje.append([opis, typ, kwota])
self.tabela.insert("", "end", values=(opis, typ, f"{kwota:.2f}"))
self.aktualizuj_saldo()
root = tk.Tk()
app = AplikacjaRozliczeniowa(root)
root.mainloop()import tkinter as tk
from tkinter import ttk, messagebox
import csv
import os
PLIK = "rozliczenia.csv"
class AplikacjaRozliczeniowa:
def __init__(self, root):
self.root = root
self.root.title("Aplikacja Rozliczeniowa")
self.root.geometry("700x500")
self.operacje = []
self.utworz_gui()
self.wczytaj_dane()
def utworz_gui(self):
frame = tk.Frame(self.root)
frame.pack(pady=10)
tk.Label(frame, text="Opis").grid(row=0, column=0)
self.opis = tk.Entry(frame, width=25)
self.opis.grid(row=0, column=1)
tk.Label(frame, text="Kwota").grid(row=1, column=0)
self.kwota = tk.Entry(frame)
self.kwota.grid(row=1, column=1)
tk.Label(frame, text="Typ").grid(row=2, column=0)
self.typ = ttk.Combobox(frame, values=["Przychód", "Wydatek"])
self.typ.current(0)
self.typ.grid(row=2, column=1)
tk.Button(frame, text="Dodaj", command=self.dodaj_operacje).grid(row=3, column=0, columnspan=2, pady=10)
self.tabela = ttk.Treeview(self.root, columns=("Opis", "Typ", "Kwota"), show="headings")
self.tabela.heading("Opis", text="Opis")
self.tabela.heading("Typ", text="Typ")
self.tabela.heading("Kwota", text="Kwota")
self.tabela.pack(fill="both", expand=True, padx=10)
self.saldo_label = tk.Label(self.root, text="Saldo: 0.00 zł", font=("Arial", 14))
self.saldo_label.pack(pady=10)
def dodaj_operacje(self):
opis = self.opis.get()
try:
kwota = float(self.kwota.get())
except ValueError:
messagebox.showerror("Błąd", "Podaj poprawną kwotę.")
return
typ = self.typ.get()
self.operacje.append([opis, typ, kwota])
self.tabela.insert("", "end", values=(opis, typ, f"{kwota:.2f}"))
self.zapisz_dane()
self.aktualizuj_saldo()
self.opis.delete(0, tk.END)
self.kwota.delete(0, tk.END)
def aktualizuj_saldo(self):
saldo = 0
for opis, typ, kwota in self.operacje:
if typ == "Przychód":
saldo += kwota
else:
saldo -= kwota
self.saldo_label.config(text=f"Saldo: {saldo:.2f} zł")
def zapisz_dane(self):
with open(PLIK, "w", newline="", encoding="utf-8") as f:
writer = csv.writer(f)
writer.writerows(self.operacje)
def wczytaj_dane(self):
if not os.path.exists(PLIK):
return
with open(PLIK, "r", encoding="utf-8") as f:
reader = csv.reader(f)
for wiersz in reader:
opis, typ, kwota = wiersz
kwota = float(kwota)
self.operacje.append([opis, typ, kwota])
self.tabela.insert("", "end", values=(opis, typ, f"{kwota:.2f}"))
self.aktualizuj_saldo()
root = tk.Tk()
app = AplikacjaRozliczeniowa(root)
root.mainloop()import tkinter as tk
from tkinter import ttk, messagebox
import csv
import os
PLIK = "rozliczenia.csv"
class AplikacjaRozliczeniowa:
def __init__(self, root):
self.root = root
self.root.title("Aplikacja Rozliczeniowa")
self.root.geometry("700x500")
self.operacje = []
self.utworz_gui()
self.wczytaj_dane()
def utworz_gui(self):
frame = tk.Frame(self.root)
frame.pack(pady=10)
tk.Label(frame, text="Opis").grid(row=0, column=0)
self.opis = tk.Entry(frame, width=25)
self.opis.grid(row=0, column=1)
tk.Label(frame, text="Kwota").grid(row=1, column=0)
self.kwota = tk.Entry(frame)
self.kwota.grid(row=1, column=1)
tk.Label(frame, text="Typ").grid(row=2, column=0)
self.typ = ttk.Combobox(frame, values=["Przychód", "Wydatek"])
self.typ.current(0)
self.typ.grid(row=2, column=1)
tk.Button(frame, text="Dodaj", command=self.dodaj_operacje).grid(row=3, column=0, columnspan=2, pady=10)
self.tabela = ttk.Treeview(self.root, columns=("Opis", "Typ", "Kwota"), show="headings")
self.tabela.heading("Opis", text="Opis")
self.tabela.heading("Typ", text="Typ")
self.tabela.heading("Kwota", text="Kwota")
self.tabela.pack(fill="both", expand=True, padx=10)
self.saldo_label = tk.Label(self.root, text="Saldo: 0.00 zł", font=("Arial", 14))
self.saldo_label.pack(pady=10)
def dodaj_operacje(self):
opis = self.opis.get()
try:
kwota = float(self.kwota.get())
except ValueError:
messagebox.showerror("Błąd", "Podaj poprawną kwotę.")
return
typ = self.typ.get()
self.operacje.append([opis, typ, kwota])
self.tabela.insert("", "end", values=(opis, typ, f"{kwota:.2f}"))
self.zapisz_dane()
self.aktualizuj_saldo()
self.opis.delete(0, tk.END)
self.kwota.delete(0, tk.END)
def aktualizuj_saldo(self):
saldo = 0
for opis, typ, kwota in self.operacje:
if typ == "Przychód":
saldo += kwota
else:
saldo -= kwota
self.saldo_label.config(text=f"Saldo: {saldo:.2f} zł")
def zapisz_dane(self):
with open(PLIK, "w", newline="", encoding="utf-8") as f:
writer = csv.writer(f)
writer.writerows(self.operacje)
def wczytaj_dane(self):
if not os.path.exists(PLIK):
return
with open(PLIK, "r", encoding="utf-8") as f:
reader = csv.reader(f)
for wiersz in reader:
opis, typ, kwota = wiersz
kwota = float(kwota)
self.operacje.append([opis, typ, kwota])
self.tabela.insert("", "end", values=(opis, typ, f"{kwota:.2f}"))
self.aktualizuj_saldo()
root = tk.Tk()
app = AplikacjaRozliczeniowa(root)
root.mainloop()import tkinter as tk
from tkinter import ttk, messagebox
import csv
import os
PLIK = "rozliczenia.csv"
class AplikacjaRozliczeniowa:
def __init__(self, root):
self.root = root
self.root.title("Aplikacja Rozliczeniowa")
self.root.geometry("700x500")
self.operacje = []
self.utworz_gui()
self.wczytaj_dane()
def utworz_gui(self):
frame = tk.Frame(self.root)
frame.pack(pady=10)
tk.Label(frame, text="Opis").grid(row=0, column=0)
self.opis = tk.Entry(frame, width=25)
self.opis.grid(row=0, column=1)
tk.Label(frame, text="Kwota").grid(row=1, column=0)
self.kwota = tk.Entry(frame)
self.kwota.grid(row=1, column=1)
tk.Label(frame, text="Typ").grid(row=2, column=0)
self.typ = ttk.Combobox(frame, values=["Przychód", "Wydatek"])
self.typ.current(0)
self.typ.grid(row=2, column=1)
tk.Button(frame, text="Dodaj", command=self.dodaj_operacje).grid(row=3, column=0, columnspan=2, pady=10)
self.tabela = ttk.Treeview(self.root, columns=("Opis", "Typ", "Kwota"), show="headings")
self.tabela.heading("Opis", text="Opis")
self.tabela.heading("Typ", text="Typ")
self.tabela.heading("Kwota", text="Kwota")
self.tabela.pack(fill="both", expand=True, padx=10)
self.saldo_label = tk.Label(self.root, text="Saldo: 0.00 zł", font=("Arial", 14))
self.saldo_label.pack(pady=10)
def dodaj_operacje(self):
opis = self.opis.get()
try:
kwota = float(self.kwota.get())
except ValueError:
messagebox.showerror("Błąd", "Podaj poprawną kwotę.")
return
typ = self.typ.get()
self.operacje.append([opis, typ, kwota])
self.tabela.insert("", "end", values=(opis, typ, f"{kwota:.2f}"))
self.zapisz_dane()
self.aktualizuj_saldo()
self.opis.delete(0, tk.END)
self.kwota.delete(0, tk.END)
def aktualizuj_saldo(self):
saldo = 0
for opis, typ, kwota in self.operacje:
if typ == "Przychód":
saldo += kwota
else:
saldo -= kwota
self.saldo_label.config(text=f"Saldo: {saldo:.2f} zł")
def zapisz_dane(self):
with open(PLIK, "w", newline="", encoding="utf-8") as f:
writer = csv.writer(f)
writer.writerows(self.operacje)
def wczytaj_dane(self):
if not os.path.exists(PLIK):
return
with open(PLIK, "r", encoding="utf-8") as f:
reader = csv.reader(f)
for wiersz in reader:
opis, typ, kwota = wiersz
kwota = float(kwota)
self.operacje.append([opis, typ, kwota])
self.tabela.insert("", "end", values=(opis, typ, f"{kwota:.2f}"))
self.aktualizuj_saldo()
root = tk.Tk()
app = AplikacjaRozliczeniowa(root)
root.mainloop()import tkinter as tk
from tkinter import ttk, messagebox
import csv
import os
PLIK = "rozliczenia.csv"
class AplikacjaRozliczeniowa:
def __init__(self, root):
self.root = root
self.root.title("Aplikacja Rozliczeniowa")
self.root.geometry("700x500")
self.operacje = []
self.utworz_gui()
self.wczytaj_dane()
def utworz_gui(self):
frame = tk.Frame(self.root)
frame.pack(pady=10)
tk.Label(frame, text="Opis").grid(row=0, column=0)
self.opis = tk.Entry(frame, width=25)
self.opis.grid(row=0, column=1)
tk.Label(frame, text="Kwota").grid(row=1, column=0)
self.kwota = tk.Entry(frame)
self.kwota.grid(row=1, column=1)
tk.Label(frame, text="Typ").grid(row=2, column=0)
self.typ = ttk.Combobox(frame, values=["Przychód", "Wydatek"])
self.typ.current(0)
self.typ.grid(row=2, column=1)
tk.Button(frame, text="Dodaj", command=self.dodaj_operacje).grid(row=3, column=0, columnspan=2, pady=10)
self.tabela = ttk.Treeview(self.root, columns=("Opis", "Typ", "Kwota"), show="headings")
self.tabela.heading("Opis", text="Opis")
self.tabela.heading("Typ", text="Typ")
self.tabela.heading("Kwota", text="Kwota")
self.tabela.pack(fill="both", expand=True, padx=10)
self.saldo_label = tk.Label(self.root, text="Saldo: 0.00 zł", font=("Arial", 14))
self.saldo_label.pack(pady=10)
def dodaj_operacje(self):
opis = self.opis.get()
try:
kwota = float(self.kwota.get())
except ValueError:
messagebox.showerror("Błąd", "Podaj poprawną kwotę.")
return
typ = self.typ.get()
self.operacje.append([opis, typ, kwota])
self.tabela.insert("", "end", values=(opis, typ, f"{kwota:.2f}"))
self.zapisz_dane()
self.aktualizuj_saldo()
self.opis.delete(0, tk.END)
self.kwota.delete(0, tk.END)
def aktualizuj_saldo(self):
saldo = 0
for opis, typ, kwota in self.operacje:
if typ == "Przychód":
saldo += kwota
else:
saldo -= kwota
self.saldo_label.config(text=f"Saldo: {saldo:.2f} zł")
def zapisz_dane(self):
with open(PLIK, "w", newline="", encoding="utf-8") as f:
writer = csv.writer(f)
writer.writerows(self.operacje)
def wczytaj_dane(self):
if not os.path.exists(PLIK):
return
with open(PLIK, "r", encoding="utf-8") as f:
reader = csv.reader(f)
for wiersz in reader:
opis, typ, kwota = wiersz
kwota = float(kwota)
self.operacje.append([opis, typ, kwota])
self.tabela.insert("", "end", values=(opis, typ, f"{kwota:.2f}"))
self.aktualizuj_saldo()
root = tk.Tk()
app = AplikacjaRozliczeniowa(root)
root.mainloop()import tkinter as tk
from tkinter import ttk, messagebox
import csv
import os
PLIK = "rozliczenia.csv"
class AplikacjaRozliczeniowa:
def __init__(self, root):
self.root = root
self.root.title("Aplikacja Rozliczeniowa")
self.root.geometry("700x500")
self.operacje = []
self.utworz_gui()
self.wczytaj_dane()
def utworz_gui(self):
frame = tk.Frame(self.root)
frame.pack(pady=10)
tk.Label(frame, text="Opis").grid(row=0, column=0)
self.opis = tk.Entry(frame, width=25)
self.opis.grid(row=0, column=1)
tk.Label(frame, text="Kwota").grid(row=1, column=0)
self.kwota = tk.Entry(frame)
self.kwota.grid(row=1, column=1)
tk.Label(frame, text="Typ").grid(row=2, column=0)
self.typ = ttk.Combobox(frame, values=["Przychód", "Wydatek"])
self.typ.current(0)
self.typ.grid(row=2, column=1)
tk.Button(frame, text="Dodaj", command=self.dodaj_operacje).grid(row=3, column=0, columnspan=2, pady=10)
self.tabela = ttk.Treeview(self.root, columns=("Opis", "Typ", "Kwota"), show="headings")
self.tabela.heading("Opis", text="Opis")
self.tabela.heading("Typ", text="Typ")
self.tabela.heading("Kwota", text="Kwota")
self.tabela.pack(fill="both", expand=True, padx=10)
self.saldo_label = tk.Label(self.root, text="Saldo: 0.00 zł", font=("Arial", 14))
self.saldo_label.pack(pady=10)
def dodaj_operacje(self):
opis = self.opis.get()
try:
kwota = float(self.kwota.get())
except ValueError:
messagebox.showerror("Błąd", "Podaj poprawną kwotę.")
return
typ = self.typ.get()
self.operacje.append([opis, typ, kwota])
self.tabela.insert("", "end", values=(opis, typ, f"{kwota:.2f}"))
self.zapisz_dane()
self.aktualizuj_saldo()
self.opis.delete(0, tk.END)
self.kwota.delete(0, tk.END)
def aktualizuj_saldo(self):
saldo = 0
for opis, typ, kwota in self.operacje:
if typ == "Przychód":
saldo += kwota
else:
saldo -= kwota
self.saldo_label.config(text=f"Saldo: {saldo:.2f} zł")
def zapisz_dane(self):
with open(PLIK, "w", newline="", encoding="utf-8") as f:
writer = csv.writer(f)
writer.writerows(self.operacje)
def wczytaj_dane(self):
if not os.path.exists(PLIK):
return
with open(PLIK, "r", encoding="utf-8") as f:
reader = csv.reader(f)
for wiersz in reader:
opis, typ, kwota = wiersz
kwota = float(kwota)
self.operacje.append([opis, typ, kwota])
self.tabela.insert("", "end", values=(opis, typ, f"{kwota:.2f}"))
self.aktualizuj_saldo()
root = tk.Tk()
app = AplikacjaRozliczeniowa(root)
root.mainloop()import tkinter as tk
from tkinter import ttk, messagebox
import csv
import os
PLIK = "rozliczenia.csv"
class AplikacjaRozliczeniowa:
def __init__(self, root):
self.root = root
self.root.title("Aplikacja Rozliczeniowa")
self.root.geometry("700x500")
self.operacje = []
self.utworz_gui()
self.wczytaj_dane()
def utworz_gui(self):
frame = tk.Frame(self.root)
frame.pack(pady=10)
tk.Label(frame, text="Opis").grid(row=0, column=0)
self.opis = tk.Entry(frame, width=25)
self.opis.grid(row=0, column=1)
tk.Label(frame, text="Kwota").grid(row=1, column=0)
self.kwota = tk.Entry(frame)
self.kwota.grid(row=1, column=1)
tk.Label(frame, text="Typ").grid(row=2, column=0)
self.typ = ttk.Combobox(frame, values=["Przychód", "Wydatek"])
self.typ.current(0)
self.typ.grid(row=2, column=1)
tk.Button(frame, text="Dodaj", command=self.dodaj_operacje).grid(row=3, column=0, columnspan=2, pady=10)
self.tabela = ttk.Treeview(self.root, columns=("Opis", "Typ", "Kwota"), show="headings")
self.tabela.heading("Opis", text="Opis")
self.tabela.heading("Typ", text="Typ")
self.tabela.heading("Kwota", text="Kwota")
self.tabela.pack(fill="both", expand=True, padx=10)
self.saldo_label = tk.Label(self.root, text="Saldo: 0.00 zł", font=("Arial", 14))
self.saldo_label.pack(pady=10)
def dodaj_operacje(self):
opis = self.opis.get()
try:
kwota = float(self.kwota.get())
except ValueError:
messagebox.showerror("Błąd", "Podaj poprawną kwotę.")
return
typ = self.typ.get()
self.operacje.append([opis, typ, kwota])
self.tabela.insert("", "end", values=(opis, typ, f"{kwota:.2f}"))
self.zapisz_dane()
self.aktualizuj_saldo()
self.opis.delete(0, tk.END)
self.kwota.delete(0, tk.END)
def aktualizuj_saldo(self):
saldo = 0
for opis, typ, kwota in self.operacje:
if typ == "Przychód":
saldo += kwota
else:
saldo -= kwota
self.saldo_label.config(text=f"Saldo: {saldo:.2f} zł")
def zapisz_dane(self):
with open(PLIK, "w", newline="", encoding="utf-8") as f:
writer = csv.writer(f)
writer.writerows(self.operacje)
def wczytaj_dane(self):
if not os.path.exists(PLIK):
return
with open(PLIK, "r", encoding="utf-8") as f:
reader = csv.reader(f)
for wiersz in reader:
opis, typ, kwota = wiersz
kwota = float(kwota)
self.operacje.append([opis, typ, kwota])
self.tabela.insert("", "end", values=(opis, typ, f"{kwota:.2f}"))
self.aktualizuj_saldo()
root = tk.Tk()
app = AplikacjaRozliczeniowa(root)
root.mainloop()
import pygame
import random
pygame.init()
# Rozmiary
CELL = 30
COLS = 10
ROWS = 20
WIDTH = COLS * CELL
HEIGHT = ROWS * CELL
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Tetris")
clock = pygame.time.Clock()
# Kolory
BLACK = (0, 0, 0)
GRAY = (40, 40, 40)
COLORS = [
(0, 255, 255),
(255, 255, 0),
(128, 0, 128),
(0, 255, 0),
(255, 0, 0),
(0, 0, 255),
(255, 165, 0),
]
SHAPES = [
[[1, 1, 1, 1]],
[[1, 1],
[1, 1]],
[[0, 1, 0],
[1, 1, 1]],
[[0, 1, 1],
[1, 1, 0]],
[[1, 1, 0],
[0, 1, 1]],
[[1, 0, 0],
[1, 1, 1]],
[[0, 0, 1],
[1, 1, 1]]
]
class Piece:
def __init__(self):
self.shape = random.choice(SHAPES)
self.color = random.choice(COLORS)
self.x = COLS // 2 - len(self.shape[0]) // 2
self.y = 0
def rotate(self):
self.shape = [list(row) for row in zip(*self.shape[::-1])]
grid = [[None for _ in range(COLS)] for _ in range(ROWS)]
piece = Piece()
def collision(px, py, shape):
for y, row in enumerate(shape):
for x, cell in enumerate(row):
if cell:
nx = px + x
ny = py + y
if nx < 0 or nx >= COLS or ny >= ROWS:
return True
if ny >= 0 and grid[ny][nx]:
return True
return False
def merge():
for y, row in enumerate(piece.shape):
for x, cell in enumerate(row):
if cell:
grid[piece.y + y][piece.x + x] = piece.color
def clear_lines():
global grid
new_grid = [row for row in grid if None in row]
removed = ROWS - len(new_grid)
while len(new_grid) < ROWS:
new_grid.insert(0, [None] * COLS)
grid = new_grid
return removed
fall_time = 0
fall_speed = 500
running = True
while running:
dt = clock.tick(60)
fall_time += dt
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
if not collision(piece.x - 1, piece.y, piece.shape):
piece.x -= 1
elif event.key == pygame.K_RIGHT:
if not collision(piece.x + 1, piece.y, piece.shape):
piece.x += 1
elif event.key == pygame.K_DOWN:
if not collision(piece.x, piece.y + 1, piece.shape):
piece.y += 1
elif event.key == pygame.K_UP:
old = [row[:] for row in piece.shape]
piece.rotate()
if collision(piece.x, piece.y, piece.shape):
piece.shape = old
if fall_time > fall_speed:
fall_time = 0
if not collision(piece.x, piece.y + 1, piece.shape):
piece.y += 1
else:
merge()
clear_lines()
piece = Piece()
if collision(piece.x, piece.y, piece.shape):
running = False
screen.fill(BLACK)
# Plansza
for y in range(ROWS):
for x in range(COLS):
pygame.draw.rect(
screen,
GRAY,
(x * CELL, y * CELL, CELL, CELL),
1
)
if grid[y][x]:
pygame.draw.rect(
screen,
grid[y][x],
(x * CELL + 1, y * CELL + 1, CELL - 2, CELL - 2)
)
# Aktualny klocek
for y, row in enumerate(piece.shape):
for x, cell in enumerate(row):
if cell:
pygame.draw.rect(
screen,
piece.color,
(
(piece.x + x) * CELL + 1,
(piece.y + y) * CELL + 1,
CELL - 2,
CELL - 2,
),
)
pygame.display.flip()
pygame.quit()import pygame
import random
pygame.init()
# Rozmiary
CELL = 30
COLS = 10
ROWS = 20
WIDTH = COLS * CELL
HEIGHT = ROWS * CELL
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Tetris")
clock = pygame.time.Clock()
# Kolory
BLACK = (0, 0, 0)
GRAY = (40, 40, 40)
COLORS = [
(0, 255, 255),
(255, 255, 0),
(128, 0, 128),
(0, 255, 0),
(255, 0, 0),
(0, 0, 255),
(255, 165, 0),
]
SHAPES = [
[[1, 1, 1, 1]],
[[1, 1],
[1, 1]],
[[0, 1, 0],
[1, 1, 1]],
[[0, 1, 1],
[1, 1, 0]],
[[1, 1, 0],
[0, 1, 1]],
[[1, 0, 0],
[1, 1, 1]],
[[0, 0, 1],
[1, 1, 1]]
]
class Piece:
def __init__(self):
self.shape = random.choice(SHAPES)
self.color = random.choice(COLORS)
self.x = COLS // 2 - len(self.shape[0]) // 2
self.y = 0
def rotate(self):
self.shape = [list(row) for row in zip(*self.shape[::-1])]
grid = [[None for _ in range(COLS)] for _ in range(ROWS)]
piece = Piece()
def collision(px, py, shape):
for y, row in enumerate(shape):
for x, cell in enumerate(row):
if cell:
nx = px + x
ny = py + y
if nx < 0 or nx >= COLS or ny >= ROWS:
return True
if ny >= 0 and grid[ny][nx]:
return True
return False
def merge():
for y, row in enumerate(piece.shape):
for x, cell in enumerate(row):
if cell:
grid[piece.y + y][piece.x + x] = piece.color
def clear_lines():
global grid
new_grid = [row for row in grid if None in row]
removed = ROWS - len(new_grid)
while len(new_grid) < ROWS:
new_grid.insert(0, [None] * COLS)
grid = new_grid
return removed
fall_time = 0
fall_speed = 500
running = True
while running:
dt = clock.tick(60)
fall_time += dt
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
if not collision(piece.x - 1, piece.y, piece.shape):
piece.x -= 1
elif event.key == pygame.K_RIGHT:
if not collision(piece.x + 1, piece.y, piece.shape):
piece.x += 1
elif event.key == pygame.K_DOWN:
if not collision(piece.x, piece.y + 1, piece.shape):
piece.y += 1
elif event.key == pygame.K_UP:
old = [row[:] for row in piece.shape]
piece.rotate()
if collision(piece.x, piece.y, piece.shape):
piece.shape = old
if fall_time > fall_speed:
fall_time = 0
if not collision(piece.x, piece.y + 1, piece.shape):
piece.y += 1
else:
merge()
clear_lines()
piece = Piece()
if collision(piece.x, piece.y, piece.shape):
running = False
screen.fill(BLACK)
# Plansza
for y in range(ROWS):
for x in range(COLS):
pygame.draw.rect(
screen,
GRAY,
(x * CELL, y * CELL, CELL, CELL),
1
)
if grid[y][x]:
pygame.draw.rect(
screen,
grid[y][x],
(x * CELL + 1, y * CELL + 1, CELL - 2, CELL - 2)
)
# Aktualny klocek
for y, row in enumerate(piece.shape):
for x, cell in enumerate(row):
if cell:
pygame.draw.rect(
screen,
piece.color,
(
(piece.x + x) * CELL + 1,
(piece.y + y) * CELL + 1,
CELL - 2,
CELL - 2,
),
)
pygame.display.flip()
pygame.quit()import pygame
import random
pygame.init()
# Rozmiary
CELL = 30
COLS = 10
ROWS = 20
WIDTH = COLS * CELL
HEIGHT = ROWS * CELL
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Tetris")
clock = pygame.time.Clock()
# Kolory
BLACK = (0, 0, 0)
GRAY = (40, 40, 40)
COLORS = [
(0, 255, 255),
(255, 255, 0),
(128, 0, 128),
(0, 255, 0),
(255, 0, 0),
(0, 0, 255),
(255, 165, 0),
]
SHAPES = [
[[1, 1, 1, 1]],
[[1, 1],
[1, 1]],
[[0, 1, 0],
[1, 1, 1]],
[[0, 1, 1],
[1, 1, 0]],
[[1, 1, 0],
[0, 1, 1]],
[[1, 0, 0],
[1, 1, 1]],
[[0, 0, 1],
[1, 1, 1]]
]
class Piece:
def __init__(self):
self.shape = random.choice(SHAPES)
self.color = random.choice(COLORS)
self.x = COLS // 2 - len(self.shape[0]) // 2
self.y = 0
def rotate(self):
self.shape = [list(row) for row in zip(*self.shape[::-1])]
grid = [[None for _ in range(COLS)] for _ in range(ROWS)]
piece = Piece()
def collision(px, py, shape):
for y, row in enumerate(shape):
for x, cell in enumerate(row):
if cell:
nx = px + x
ny = py + y
if nx < 0 or nx >= COLS or ny >= ROWS:
return True
if ny >= 0 and grid[ny][nx]:
return True
return False
def merge():
for y, row in enumerate(piece.shape):
for x, cell in enumerate(row):
if cell:
grid[piece.y + y][piece.x + x] = piece.color
def clear_lines():
global grid
new_grid = [row for row in grid if None in row]
removed = ROWS - len(new_grid)
while len(new_grid) < ROWS:
new_grid.insert(0, [None] * COLS)
grid = new_grid
return removed
fall_time = 0
fall_speed = 500
running = True
while running:
dt = clock.tick(60)
fall_time += dt
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
if not collision(piece.x - 1, piece.y, piece.shape):
piece.x -= 1
elif event.key == pygame.K_RIGHT:
if not collision(piece.x + 1, piece.y, piece.shape):
piece.x += 1
elif event.key == pygame.K_DOWN:
if not collision(piece.x, piece.y + 1, piece.shape):
piece.y += 1
elif event.key == pygame.K_UP:
old = [row[:] for row in piece.shape]
piece.rotate()
if collision(piece.x, piece.y, piece.shape):
piece.shape = old
if fall_time > fall_speed:
fall_time = 0
if not collision(piece.x, piece.y + 1, piece.shape):
piece.y += 1
else:
merge()
clear_lines()
piece = Piece()
if collision(piece.x, piece.y, piece.shape):
running = False
screen.fill(BLACK)
# Plansza
for y in range(ROWS):
for x in range(COLS):
pygame.draw.rect(
screen,
GRAY,
(x * CELL, y * CELL, CELL, CELL),
1
)
if grid[y][x]:
pygame.draw.rect(
screen,
grid[y][x],
(x * CELL + 1, y * CELL + 1, CELL - 2, CELL - 2)
)
# Aktualny klocek
for y, row in enumerate(piece.shape):
for x, cell in enumerate(row):
if cell:
pygame.draw.rect(
screen,
piece.color,
(
(piece.x + x) * CELL + 1,
(piece.y + y) * CELL + 1,
CELL - 2,
CELL - 2,
),
)
pygame.display.flip()
pygame.quit()import tkinter as tk
from tkinter import ttk, messagebox
import csv
import os
PLIK = "rozliczenia.csv"
class AplikacjaRozliczeniowa:
def __init__(self, root):
self.root = root
self.root.title("Aplikacja Rozliczeniowa")
self.root.geometry("700x500")
self.operacje = []
self.utworz_gui()
self.wczytaj_dane()
def utworz_gui(self):
frame = tk.Frame(self.root)
frame.pack(pady=10)
tk.Label(frame, text="Opis").grid(row=0, column=0)
self.opis = tk.Entry(frame, width=25)
self.opis.grid(row=0, column=1)
tk.Label(frame, text="Kwota").grid(row=1, column=0)
self.kwota = tk.Entry(frame)
self.kwota.grid(row=1, column=1)
tk.Label(frame, text="Typ").grid(row=2, column=0)
self.typ = ttk.Combobox(frame, values=["Przychód", "Wydatek"])
self.typ.current(0)
self.typ.grid(row=2, column=1)
tk.Button(frame, text="Dodaj", command=self.dodaj_operacje).grid(row=3, column=0, columnspan=2, pady=10)
self.tabela = ttk.Treeview(self.root, columns=("Opis", "Typ", "Kwota"), show="headings")
self.tabela.heading("Opis", text="Opis")
self.tabela.heading("Typ", text="Typ")
self.tabela.heading("Kwota", text="Kwota")
self.tabela.pack(fill="both", expand=True, padx=10)
self.saldo_label = tk.Label(self.root, text="Saldo: 0.00 zł", font=("Arial", 14))
self.saldo_label.pack(pady=10)
def dodaj_operacje(self):
opis = self.opis.get()
try:
kwota = float(self.kwota.get())
except ValueError:
messagebox.showerror("Błąd", "Podaj poprawną kwotę.")
return
typ = self.typ.get()
self.operacje.append([opis, typ, kwota])
self.tabela.insert("", "end", values=(opis, typ, f"{kwota:.2f}"))
self.zapisz_dane()
self.aktualizuj_saldo()
self.opis.delete(0, tk.END)
self.kwota.delete(0, tk.END)
def aktualizuj_saldo(self):
saldo = 0
for opis, typ, kwota in self.operacje:
if typ == "Przychód":
saldo += kwota
else:
saldo -= kwota
self.saldo_label.config(text=f"Saldo: {saldo:.2f} zł")
def zapisz_dane(self):
with open(PLIK, "w", newline="", encoding="utf-8") as f:
writer = csv.writer(f)
writer.writerows(self.operacje)
def wczytaj_dane(self):
if not os.path.exists(PLIK):
return
with open(PLIK, "r", encoding="utf-8") as f:
reader = csv.reader(f)
for wiersz in reader:
opis, typ, kwota = wiersz
kwota = float(kwota)
self.operacje.append([opis, typ, kwota])
self.tabela.insert("", "end", values=(opis, typ, f"{kwota:.2f}"))
self.aktualizuj_saldo()
root = tk.Tk()
app = AplikacjaRozliczeniowa(root)
root.mainloop()
pygame(quit)
To embed this project on your website, copy the following code and paste it into your website's HTML: