🧑💻 Добро пожаловать в канал по программированию! Не знал с чего начать свой путь в IT? Тогда заходи, потому что у нас рассказывается про языки Python и <Html, CSS, Javascript>! Этот канал не только поможет тебе выбрать твой первый язык, но еще здесь собраны все коды для профи и для начинашек!
🧑💻 🔠 акже все сложено по полочкам: посмотри навигацию, там все подписано! :3
🌟 @PythonPygame
Please open Telegram to view this post
VIEW IN TELEGRAM
❤🔥8
😊 Прайс-лист на ботов: https://t.me/PythonPygame/185
😊 ОБЩИЙ БОТ: @RockyGidraBOT
😊 Пиар пост: https://t.me/PythonPygame/3
😊 Важные ссылки:
🎩 Моя игра: https://t.me/PythonPygame/326
Please open Telegram to view this post
VIEW IN TELEGRAM
❤🔥9 7🥰3👏1 1
pip install pygameimport pygame #Импортируем
pygame.init() #Инициализируем
#Python
#Pygame
#Начало@PythonPygame
Please open Telegram to view this post
VIEW IN TELEGRAM
#Импортируем Pygame
import pygame
#Инициализируем Pygame
pygame.init()
#Создаем окну размер и название
window = pygame.display.set_mode((800, 600))
screen = pygame.Surface((800, 600))
pygame.display.set_caption("Test")
#Бесконечный цикл, чтобы окно не лагало
start = True
while start:
for i in pygame.event.get():
if i.type == pygame.QUIT:
start = False
window.blit(screen,(0,0)) #Заполняем окно
screen.blit((0,0,0)) #Заполняем экран
pygame.display.update() #Обновляем окно
#Выходим из Pygame
pygame.quit()
#Python
#Pygame
#Окно@PythonPygame
Please open Telegram to view this post
VIEW IN TELEGRAM
import pygame
#Импортируем библиотеку, которая поддерживает Gif
import gif_pygame
pygame.init()
#Делаем окно и задаем ему размеры
window = pygame.display.set_mode((800, 600))
screen = pygame.Surface((800, 600))
#Делаем Gif
example_gif = gif_pygame.load("your_gif.gif") #Сюда пишем ваше название файла вашего .gif.
#Создаем поверхности
s1 = pygame.Surface((66, 66))
s2 = pygame.Surface((66, 66))
s3 = pygame.Surface((66, 66))
#Заполняем поверхности
s1.fill((255, 0, 0))
s2.fill((0, 255, 0))
s3.fill((0, 0, 255))
#Создание объекта GifPygame
example_surfs = gif_pygame.GIFPygame([(s1, 1), (s2, 1), (s3, 1)])
#Даем позицию Gif
x_gif = 0
y_gif = 0
#Делаем бесконечный цикл для окна
start = True
while start:
for i in pygame.event.get():
if i.type == pygame.QUIT:
start = False
window.blit(screen,(0,0)) #Заполняем экран
screen.blit(example_gif.blit_ready(), (x_gif y_gif)) #Отображаем Gif
pygame.display.update()
pygame.quit()
#Pygame
#Python
#Гифки@PythonPygame
Please open Telegram to view this post
VIEW IN TELEGRAM
import pygame
pygame.init()
window = pygame.display.set_mode((800, 600))
screen = pygame.Surface((800, 600))
cube = pygame.Surface((100, 100)) #Создаем кубик на экране
x_cube = 0 #Задаем позицию по оси x
y_cube = 0 #Задаем позицию по оси y
start = True
while start:
for i in pygame.event.get():
if i.type == pygame.QUIT:
start = False
if i.type == pygame.KEYDOWN and i.key == pygame.K_d: #Делаем условие для клавиши D (она обозначает вправо)
y_cube += 0 #По оси y
x_cube += 10 #По оси x
if i.type == pygame.KEYDOWN and i.key == pygame.K_a: #Делаем передвижение влево
y_cube += 0
x_cube += -10
if i.type == pygame.KEYDOWN and i.key == pygame.K_s: #Делаем передвижение вниз
y_cube += 10
x_cube += 0
if i.type == pygame.KEYDOWN and i.key == pygame.K_w: #Делаем передвижение вверх
y_cube += -10
x_cube += 0
window.blit(screen,(0,0))
screen.blit(cube, (x_cube, y_cube)) #Отображаем кубик
pygame.display.update()
pygame.quit()
#Pygame
#Python
#Передвижение@PythonPygame
Please open Telegram to view this post
VIEW IN TELEGRAM
button.py . Для отображения код будет другой, но покажу я его позже. Этот код можете скопировать, в коде ничего менять не надоimport pygame #Импортируем Pygame в класс кнопки.
#Создаем класс кнопки и добавлем ей ось x, ось y, высоту, ширину, текст, сама картинка, картинка при нажатии и звук.
class Settingbutton:
def init(self, x, y, width, height, text, image_path, hover_image_path=None, sound_path=None):
self.x = x
self.y = y
self.width = width
self.height = height
self.text = text
self.image = pygame.image.load(image_path)
self.image = pygame.transform.scale(self.image, (width, height))
self.hover_image = self.image
if hover_image_path:
self.hover_image = pygame.image.load(hover_image_path)
self.hover_image = pygame.transform.scale(self.hover_image, (width, height))
self.rect = self.image.get_rect(topleft=(x, y))
self.sound = None
if sound_path:
self.sound = pygame.mixer.Sound(sound_path)
self.is_hovered = False
def draw(self, screen):
current_image = self.hover_image if self.is_hovered else self.image
screen.blit(current_image, self.rect.topleft)
font = pygame.font.Font(None, 36)
text_surface = font.render(self.text, True, (255, 255, 255))
text_rect = text_surface.get_rect(center=self.rect.center)
screen.blit(text_surface, text_rect)
def check_hover(self, mouse_pos):
self.is_hovered = self.rect.collidepoint(mouse_pos)
def handle_event(self, event):
if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1 and self.is_hovered:
if self.sound:
self.sound.play()
pygame.event.post(pygame.event.Event(pygame.USEREVENT, button=self))
#Python
#Pygame
#КлассКнопки@PythonPygame
Please open Telegram to view this post
VIEW IN TELEGRAM
import pygame
import os
from button import Settingbutton #Импортируем класс кнопки в главный код
pygame.init()
window = pygame.display.set_mode((WIDTH, HEIGHT))
WIDTH, HEIGHT = 800, 600
screen = pygame.Surface((WIDTH, HEIGHT))
image = pygame.image.load('image.jpg') #Загружаем картинку для кнопки
hover_image = pygame.image.load('hover_image.jpg') #Загружаем картинку для наведения кнопки
settingbutton = Settingbutton(WIDTH / 2 - (252 / 2), 100, 252, 74, 'Settings', 'image.jpg', 'hover_image.jpg') #До бесконечного цикла загружаем кнопку
start = True
while start:
for event in pygame.event.get():
if event.type == pygame.QUIT:
start = False
pygame.quit()
for btn in [settingbutton]:
btn.handle_event(event) #Отображаем кнопку
settingbutton.check_hover(pygame.mouse.get_pos()) #Отображаем кнопку при наведении мышки
settingbutton.draw(screen) #Рисуем кнопку
window.blit(screen, (0, 0))
screen.blit(0,0,0))
pygame.display.flip()
pygame.quit()
#Python
#Pygame
#Кнопка@PythonPygame
Please open Telegram to view this post
VIEW IN TELEGRAM
import pygame
pygame.init()
window = pygame.display.set_mode((WIDTH, HEIGHT))
WIDTH, HEIGHT = 800, 600
screen = pygame.Surface((WIDTH, HEIGHT))
pygame.display.set_caption("Test")
icon = pygame.image.load('icon.png') #Загружаем вашу картинку для иконки
pygame.display.set_icon(icon) #Отображаем иконку
#И такой же бесконечный цикл
start = True
while start:
for i in pygame.event.get():
if i.type == pygame.QUIT:
start = False
screen.blit((0, 0, 0))
window.blit(screen,(0,0))
pygame.display.update()
pygame.quit()
#Python
#Pygame
#Иконка@PythonPygame
Please open Telegram to view this post
VIEW IN TELEGRAM
import pygame
pygame.init()
window = pygame.display.set_mode((WIDTH, HEIGHT))
WIDTH, HEIGHT = 800, 600
screen = pygame.Surface((WIDTH, HEIGHT))
pygame.display.set_caption("Test")
icon = pygame.image.load('image.png')
pygame.display.set_icon(icon)
bg = pygame.image.load('bg.png') #Загружаем картинку для фона
start = True
while start:
screen.fill((0, 0, 0)) #Заливаем фон черным в начале
screen.blit(bg, (0, 0)) #И добавляем картинку
for i in pygame.event.get():
if i.type == pygame.QUIT:
start = False
window.blit(screen,(0,0))
screen.blit(bg, (0, 0)) #Отображаем фон
pygame.display.update()
pygame.quit()
#Python
#Pygame
#Фон@PythonPygame
Please open Telegram to view this post
VIEW IN TELEGRAM
This media is not supported in your browser
VIEW IN TELEGRAM
import kivy
import buildozer
import pygame
from pygame import FULLSCREEN
import os
import gif_pygame
from settingbutton import Settingbutton
pygame.init()
window = pygame.display.set_mode((WIDTH, HEIGHT))
WINDOW = pygame.display.set_mode((WIDTH, HEIGHT))
WIDTH, HEIGHT = 800, 600
screen = pygame.Surface((WIDTH, HEIGHT))
pygame.display.set_caption("Test")
icon = pygame.image.load('hawkfrost.png')
pygame.display.set_icon(icon)
clock = pygame.time.Clock()
image = pygame.image.load('final.jpg')
back_gif = gif_pygame.load("bg.gif")
s1 = pygame.Surface((66, 66))
s2 = pygame.Surface((66, 66))
s3 = pygame.Surface((66, 66))
s1.fill((255, 0, 0))
s2.fill((0, 255, 0))
s3.fill((0, 0, 255))
back_surfs = gif_pygame.GIFPygame([(s1, 1), (s2, 1), (s3, 1)])
tails = gif_pygame.load("gif.gif")
s1 = pygame.Surface((66, 66))
s2 = pygame.Surface((66, 66))
s3 = pygame.Surface((66, 66))
s1.fill((255, 0, 0))
s2.fill((0, 255, 0))
s3.fill((0, 0, 255))
tails_surfs = gif_pygame.GIFPygame([(s1, 1), (s2, 1), (s3, 1)])
pygame.mixer.music.load('title.mp3')
pygame.mixer.music.play()
def main():
settingbutton = Settingbutton(WIDTH / 2 - (252 / 2), 100, 252, 74, 'Settings', 'hawkfrost.png', 'final.jpg')
start = True
while start:
screen.fill((0, 0, 0))
screen.blit(back_gif.blit_ready(), (0, 0))
for event in pygame.event.get():
if event.type == pygame.QUIT:
start = False
pygame.quit()
elif event.type == pygame.USEREVENT and event.button == settingbutton:
settings()
elif event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
window = pygame.display.set_mode((800, 600))
elif event.type == pygame.KEYDOWN and event.key == pygame.K_f:
window = pygame.display.set_mode((800, 600), FULLSCREEN)
for btn in [settingbutton]:
btn.handle_event(event)
settingbutton.check_hover(pygame.mouse.get_pos())
settingbutton.draw(screen)
WINDOW.blit(screen, (0, 0))
screen.blit(back_gif.blit_ready(), (0, 0))
pygame.display.flip()
def settings():
y_tails = 0
x_tails = 0
start = True
while start:
screen.fill((0, 0, 0))
screen.blit(image, (0, 0))
for event in pygame.event.get():
if event.type == pygame.QUIT:
start = False
pygame.quit()
elif event.type == pygame.KEYDOWN and event.key == pygame.K_d:
y_tails += 0
x_tails += 10
elif event.type == pygame.KEYDOWN and event.key == pygame.K_a:
y_tails += 0
x_tails += -10
elif event.type == pygame.KEYDOWN and event.key == pygame.K_s:
y_tails += 10
x_tails += 0
elif event.type == pygame.KEYDOWN and event.key == pygame.K_w:
y_tails += -10
x_tails += 0
elif event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
window = pygame.display.set_mode((800, 600))
elif event.type == pygame.KEYDOWN and event.key == pygame.K_f:
window = pygame.display.set_mode((800, 600), FULLSCREEN)
screen.blit(tails.blit_ready(), (x_tails, y_tails))
WINDOW.blit(screen, (0, 0))
screen.blit(image, (0, 0))
pygame.display.flip()
if __name__ == '__main__':
main()
pygame.quit()
#Python
#Pygame
#МояИгра1@PythonPygame
Please open Telegram to view this post
VIEW IN TELEGRAM
import pygame
pygame.init()
window = pygame.display.set_mode((WIDTH, HEIGHT))
WINDOW = pygame.display.set_mode((WIDTH, HEIGHT))
WIDTH, HEIGHT = 800, 600
screen = pygame.Surface((WIDTH, HEIGHT))
pygame.display.set_caption("Test")
icon = pygame.image.load("image.png")
pygame.display.set_icon(icon)
bg = pygame.image.load("bg.png")
#Создаем def и даем ему имя. У меня main
def main():
start = True
while start:
screen.fill((0, 0, 0))
screen.blit(bg, (0, 0))
for event in pygame.event.get():
if event.type == pygame.QUIT:
start = False
pygame.quit()
WINDOW.blit(screen, (0, 0))
screen.blit(bg, (0, 0))
pygame.display.flip()
#Самое важное! Без этой строчки def работать не будет! Эта строчка говорит, что первым запускаться будет def main()
if __name__ == '__main__':
main()
pygame.quit()
#Python
#Pygame
#ФункцияDef@PythonPygame
Please open Telegram to view this post
VIEW IN TELEGRAM
#Python
#Pygame
#МояИгра2@PythonPygame
Please open Telegram to view this post
VIEW IN TELEGRAM
import pygame
pygame.init()
window = pygame.display.set_mode((WIDTH, HEIGHT))
WINDOW = pygame.display.set_mode((WIDTH, HEIGHT))
WIDTH, HEIGHT = 800, 600
screen = pygame.Surface((WIDTH, HEIGHT))
pygame.display.set_caption("Test")
icon = pygame.image.load('image.png')
pygame.display.set_icon(icon)
bg = pygame.image.load('bg.png')
#Загружаем музыку на всю игру. Т. е. на все слайды
pygame.mixer.music.load('music.mp3')
pygame.mixer.music.play() #Если в скобочках ничего не ставим, то музыка будет не зацикленная. Чтобы она зациклилась надо поставить -1
def main():
start = True
while start:
screen.fill((0, 0, 0))
screen.blit(bg, (0, 0))
for event in pygame.event.get():
if event.type == pygame.QUIT:
start = False
pygame.quit()
WINDOW.blit(screen, (0, 0))
screen.blit(bg, (0, 0))
pygame.display.flip()
if __name__ == '__main__':
main()
pygame.quit()
#Python
#Pygame
#Музыка@PythonPygame
Please open Telegram to view this post
VIEW IN TELEGRAM
import pygame
pygame.init()
pygame.display.set_caption("Test")
icon = pygame.image.load('hawkfrost.png')
pygame.display.set_icon(icon)
bg = pygame.image.load('image.png')
image = pygame.image.load('image.jpg') #Добавляем вашу картинку
image = pygame.transform.scale(image, (700, 200)) #Масштабируем её
screen = pygame.Surface((WIDTH, HEIGHT))
WIDTH, HEIGHT = 800, 475
def main():
screen = pygame.Surface((800, 475))
window = pygame.display.set_mode((WIDTH, HEIGHT))
start = True
while start:
screen.fill((0, 0, 0))
screen.blit(bg, (0, 0))
for event in pygame.event.get():
if event.type == pygame.QUIT:
start = False
pygame.quit()
screen.blit(image, (0, 0)) #Отображаем картинку
window.blit(screen, (0, 0))
screen.blit(bg, (0, 0))
pygame.display.flip()
pygame.quit()
#Python
#Pygame
#Картинка@PythonPygame
Please open Telegram to view this post
VIEW IN TELEGRAM
🥰1
/newbot . Выполняете запросы BotFather. В конце он вам выдаст ваш личный токен вашего бота. Скопируйте его. Теперь заходим в Python и выбиваем в терминал строчку, чтобы установить библиотеку для тг бота:pip install telebotimport telebot
from telebot import types
#Python
#BotTelegram
#НачалоБот@PythonPygame
Please open Telegram to view this post
VIEW IN TELEGRAM