Hi Nick @stoochie ! It looks like you tried to do the right thing to format your code when you pasted it into the post, but it didn’t quite work out. Try like this: Edit your post and delete all the code that is there Put the cursor on a new blank line Look in the editing toolbar above the editin… Answer from flyinghyrax on discuss.python.org
🌐
GitHub
gist.github.com › sanchitgangwar › 2158089
Snakes Game using Python · GitHub
Snakes Game using Python. GitHub Gist: instantly share code, notes, and snippets.
🌐
Reddit
reddit.com › r/python › i made a pong game with pygame and i just wanted to share!
r/Python on Reddit: i made a pong game with pygame and i just wanted to share!
August 6, 2014 -

http://pastebin.com/8qwZKnPG

just copy/paste and run the code.

Notes!

  • this game is unbeatable

  • changing the difficulty only changes the fps of the game

  • do not use disco mode if you cant do flashing lights

i know the code is VERY sloppy and poorly organized but id rather get the game done quick then spend hours making the code readable.

Discussions

Coding a simple fishing game, logic being ignored (EDITED)
Hi friends, your help would be much appreciated with this one sorry in advance if i am not asking for help in the right way or have not formatted this document correctly, its my first time asking for help, please bear with me. 😀 the ‘if statement’ with asterixs ** before it is being ... More on discuss.python.org
🌐 discuss.python.org
4
0
October 9, 2023
image - "copy and paste" python program - Stack Overflow
I'm currently trying to write a program that reads a GIF file, displays its image on the screen, then allows the user to select a rectangular portion of the image to "copy and paste", AKA to then c... More on stackoverflow.com
🌐 stackoverflow.com
i made a pong game with pygame and i just wanted to share!
It's great you actually finished something! The first thing that I completely finished was a pong clone in Python/Pygame too; it's a fantastic learning tool. More on reddit.com
🌐 r/Python
9
14
August 6, 2014
how do i copy paste a code of text in python and play?

Did you have pip install curses?

More on reddit.com
🌐 r/learnpython
1
1
August 2, 2019
🌐
AskPython
askpython.com › python › examples › easy-games-in-python
Easy Games in Python - AskPython
April 20, 2026 - Python is one of the easiest languages for building your own games. You can start with text-based games using only print() and input(), then move to graphical games using the built-in turtle module or install pygame via pip install pygame. A number guessing game or a Quiz Game are the easiest starting points. Both require under 50 lines of code, use only built-in functions, and teach you core concepts like loops, conditionals, and player input.
🌐
Python.org
discuss.python.org › python help
Coding a simple fishing game, logic being ignored (EDITED) - Python Help - Discussions on Python.org
October 9, 2023 - Hi friends, your help would be much appreciated with this one sorry in advance if i am not asking for help in the right way or have not formatted this document correctly, its my first time asking for help, please bear with me. 😀 the ‘if statement’ with asterixs ** before it is being ignored (it is the first staement inside the still fishing while loop) I have tried re arranging the order of the if statements my code does not realise that I have added a catch to my esky. it will no...
🌐
Grant Jenks
grantjenks.com › docs › freegames
Free Python Games — Free Python Games 2.5.3 documentation
$ python3 -m freegames copy snake $ python3 snake.py · Python includes a built-in text editor named IDLE which can also execute Python code. To launch the editor and make changes to the “snake” game run:
🌐
Washington University in St. Louis
cse.wustl.edu › ~garnett › cse511a › code › project2 › pacman_py.html
Untitled
""" self.data.initialize(layout, numGhostAgents) ############################################################################ # THE HIDDEN SECRETS OF PACMAN # # # # You shouldn't need to look through the code in this section of the file. # ############################################################################ SCARED_TIME = 40 # Moves ghosts are scared COLLISION_TOLERANCE = 0.7 # How close ghosts must be to Pacman to kill TIME_PENALTY = 1 # Number of points lost each round class ClassicGameRules: """ These game rules manage the control flow of a game, deciding when and how the game starts and ends.
Find elsewhere
Top answer
1 of 2
2

The main problem with your code is that you create a new PhotoImage for each pixel! Instead, create the PhotoImage once and just add the pixels in the double-for-loop.

def box(event):
    yaxis(event)
    canvas.create_rectangle(x1, y1, x2, y2)

    picture = PhotoImage(width=(x2-x1), height=(y2-y1))
    for x in range(x1, x2):
        for y in range(y1, y2):
            r, g, b = photo.get(x, y)
            picture.put("#%02x%02x%02x" % (r, g, b), (x-x1, y-y1))
    picture.write('new_image.gif', format='gif')

Also, the line tuple(map(int, value.split(" "))) in your getRGB function is wrong, as value is already the tuple you want to create, not a string.1) As you can see, I just 'inlined' that part directly into the box function. Another problem was that you wrote the copied pixels to x and y, but you have to write them to x-x1 and y-y1 instead.

Update 1: 1) It seems like the return value of PhotoImage.get depends on the version of Python/Tkinter you are using. In some versions, it returns a tuple, like (41, 68, 151), and in others, a string, like u'41 68 151'.

Update 2: As pointed out by @Oblivion, you can in fact just use the from_coords parameter of PhotoImage.write to specify the region of the picture to be saved to file. With this, the box function can be simplified as

def box(event):
    yaxis(event)
    canvas.create_rectangle(x1, y1, x2, y2)
    photo.write('new_image.gif', format='gif', from_coords=[x1, y1, x2, y2])
2 of 2
0
import tkinter
from tkinter import *
import base64

root = Tk()

def action(canvas):
    canvas.bind("<Button-1>", xaxis)
    canvas.bind("<ButtonRelease-1>", yaxis)
    canvas.bind("<ButtonRelease-1>", box)

def xaxis(event):
    global x1, y1
    x1, y1 = (event.x - 1), (event.y - 1)
    print (x1, y1)

def yaxis(event):
    global x2, y2
    x2, y2 = (event.x + 1), (event.y + 1)
    print (x2, y2)

def box(event, photo):
    x1, y1 = (event.x - 1), (event.y - 1)
    x2, y2 = (event.x + 1), (event.y + 1)
    canvas.create_rectangle(x1, y1, x2, y2)
    new_photo = copy_photo(photo, x1, y1, x2, y2)
    new_photo.write('new_image.gif', format='gif')

def copy_photo(photo, x1, y1, x2, y2):
    new_photo = PhotoImage(width=photo.width(), height=photo.height())
    for x in range(photo.width()):
        for y in range(photo.height()):
            if x1 <= x < x2 and y1 <= y < y2:
                r,g,b = getRGB(photo, x, y)
                new_photo.put("#%02x%02x%02x" % (r,g,b), (x,y))
            else:
                new_photo.put(photo.get(x, y), (x,y))
    return new_photo

def getRGB(photo, x, y):
    value = photo.get(x, y)
    return tuple(map(int, value.split(" ")))

canvas = Canvas(width=500, height=250)
canvas.pack(expand=YES, fill=BOTH)
photo = PhotoImage(file="picture.gif")
canvas.create_image(0, 0, image=photo, anchor=NW)
canvas.config(cursor='cross')
action(canvas)

enter code here

canvas.mainloop()
🌐
ActiveState
code.activestate.com › recipes › 578816-the-game-of-tic-tac-toe-in-python
The Game of Tic Tac Toe in Python « Python recipes « ActiveState Code
January 31, 2014 - Classic game but lacking in graphics :P Check out Tic-tac-toe in Free Python Games at http://www.grantjenks.com/docs/freegames/ You can just do "python3 -m pip install freegames" and then "python3 -m freegames.tictactoe" That includes a complete visual interface in just 57 lines of Python code!
🌐
Anirudh Jayaraman
pythonandr.com › 2015 › 05 › 16 › code-for-my-first-text-based-game
Code for my First Text-Based Game – Anirudh Jayaraman
July 6, 2015 - You can simply copy the code below into a text file, naming it something like game.py and save it to your home directory or wherever you wish to and run game.py from. Then from Terminal (CMD for Windows), type in python game.py.
🌐
PyPI
pypi.org › project › gamesbyexample
gamesbyexample · PyPI
They fit into a single source code file and have no installer. This makes these games trivial to share by copy/pasting code to a pastebin site. Data/image/save files can be used, but the source should link to some examples in their comments. They only use the Python standard library.
      » pip install gamesbyexample
    
Published   Dec 30, 2020
Version   2020.12.30
🌐
National Health Mission
nhmmp.gov.in › online-simple-games-to-code-in-python-34537t51.html
simple games to code in python
Department of Public Health & Family Welfare, Govt.of M.P · सूचना : "अपरिहार्य कारणों के कारण, बुधवार दिनांक 15.02.2023 को होने वाले MO/PGMOs के ऑनलाइन वाकइन ...
🌐
PACMANCODE
pacmancode.com
Pacmancode
For those of you who are interested in having the complete code, here it is. Just download the file below and unzip it. This game was written with Python 3 in mind, so ensure you have Python 3 installed.
🌐
IDTech
idtech.com › blog › easy-games-to-make-in-python
9 Cool & Easy Games to Make in Python (And Starter Code for Beginners)
March 27, 2024 - We’ll explore some easy yet exciting games kids can create with Python. And while the end goal is something fun and cool, doing so helps practice fundamental programming concepts like loops, conditionals, and user input. So, grab your code editor (we use PyCharm), and let’s dive into the world of Python game development!
🌐
101 Computing
101computing.net › home › python challenges › snake game using python
Snake Game Using Python - 101 Computing
August 9, 2024 - In this Python programming challenge, we are going to revisit the classic game called Snake. In this game, the player controls a snake using the arrow keys of the keyboard. The snake can go in all four directions (up, down, left, and right).
🌐
Orbeducation
orbeducation.com › Previews › Co › CoP058_Python_Games.pdf pdf
Python Games - ORB Education Australia
Click New Trinket and select Python. ... Carefully copy the code shown below into the coding window. When you are finished, click the Run button.
🌐
GitHub
github.com › Gigert9 › Python-Games
GitHub - Gigert9/Python-Games: A bunch of simple Python games · GitHub
The code has been retyped as per each tutorial in an effor to further my knowledge of the Python language by using pygame. Reference Video: https://www.youtube.com/watch?v=XGf2GcyHPhc&t=116s · It's suggested to clone the entire github repo for playing locally, however it is possible to pull some of the individual games. Pong, Snake, and Connect Four will all work independently.
Author   Gigert9
🌐
GitHub
github.com › SanjayKotabagi › 50-Games-Using-Python
GitHub - SanjayKotabagi/50-Games-Using-Python · GitHub
cd 50-Python-Games/GameName Run the Python script for that game python game_name.py Note: Some games may have additional dependencies or setup instructions mentioned within their respective directories. Usage Instructions for playing each game are provided within their respective directories. Feel free to explore, modify, and customize the games to your liking. Experiment with the code, add features, or even combine elements from different games to create something entirely new.
Starred by 12 users
Forked by 23 users
Languages   Python
🌐
myCompiler
mycompiler.io › view › JoV6mE4H1XT
gun game (Python) - myCompiler
import pygame import random # Define colors BLACK = (0, 0, 0) WHITE = (255, 255, 255) # Set the dimensions of the screen SCREEN_WIDTH = 800 SCREEN_HEIGHT = 600 # Define the Player class class Player(pygame.sprite.Sprite): def __init__(self): super().__init__() self.image = pygame.Surface([20, 20]) self.image.fill(WHITE) self.rect = self.image.get_rect() def update(self): # Move the player based on user input keys = pygame.key.get_pressed() if keys[pygame.K_LEFT]: self.rect.x -= 5 elif keys[pygame.K_RIGHT]: self.rect.x += 5 # Keep the player within the screen bounds if self.rect.x < 0: self.rec