๐ŸŒ
Python
wiki.python.org โ€บ moin โ€บ SimplePrograms
SimplePrograms - Python Wiki
>>> median([2, 9, 9, 7, 9, 2, 4, 5, 8]) 6 #change to 7 in order to pass the test ''' copy = sorted(pool) size = len(copy) if size % 2 == 1: return copy[int((size - 1) / 2)] else: return (copy[int(size/2 - 1)] + copy[int(size/2)]) / 2 if __name__ == '__main__': import doctest doctest.testmod()
Discussions

Is there a website where I can easily copy and paste python programs?
The problem I have with GITHUB is the file download, because I can't figure out how to get the code from the files. maybe learn how to do it? More on reddit.com
๐ŸŒ r/learnpython
4
0
May 27, 2022
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
Free recommended code sharing sites?
Iโ€™m fairly new to Python, I still have not finished my first Python tutorial. Sometimes itโ€™s easier to share longer code (50+ lines) on a code sharing website. Besides pastebin.com, what are recommended code sharing sites when asking questions on a forum about Python? More on discuss.python.org
๐ŸŒ discuss.python.org
7
0
February 16, 2024
Copy and Paste Files - Command
Good night people, I have a problem, I used the following code to copy and paste files from one folder to another import os import time import shutil origem = r"C:\Program Files\Corel\CorelDRAW Graphics Suite 2022\Programs64\Pasta2" destino = r"C:\Program Files\Corel\CorelDRAW Graphics Suite ... More on discuss.python.org
๐ŸŒ discuss.python.org
3
0
June 24, 2024
๐ŸŒ
OneCompiler
onecompiler.com โ€บ python โ€บ 3wsj7ajyg
Python Online Compiler & Interpreter
Write, Run & Share Python code online using OneCompiler's Python online compiler for free. It's one of the robust, feature-rich online compilers for python language, supporting both the versions which are Python 3 and Python 2.7. Getting started with the OneCompiler's Python editor is easy and fast.
๐ŸŒ
CopyAssignment
copyassignment.com โ€บ python-games-code-copy-and-paste
Python Games Code | Copy and Paste โ€“ CopyAssignment
August 23, 2022 - Hello friends, today, we will see all the Python games code which you can easily copy and paste into your system.
๐ŸŒ
Python Morsels
pythonmorsels.com โ€บ paste
Share Python Code โ€“ a runnable Pastebin
A free Python-oriented pastebin service for sharing Python code snippets with anyone
๐ŸŒ
Java Code Geeks
javacodegeeks.com โ€บ home โ€บ web development โ€บ python
Explore These 20 Cool Python Scripts for Fun and Productivity! - Java Code Geeks
January 17, 2024 - Explore a collection of versatile Cool Python scripts, from web scraping to machine learning and web development.
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()
Find elsewhere
๐ŸŒ
Python Forum
python-forum.io โ€บ thread-14918.html
Copy & Paste Web Page
Is there a way to copy all text on a webpage and paste in a variable in Python 3.62 ? I am looking for a solution that does not use SendKeys('^a',0)/SendKeys('^c',0)
๐ŸŒ
Backlinkworks
blogs.backlinkworks.com โ€บ home โ€บ 10 insanely cool python codes youโ€™ll want to copy and paste right away!
10 Insanely Cool Python Codes You'll Want to Copy and Paste Right Away! - Topics on SEO & Backlinks
February 6, 2024 - Python is an incredibly versatile programming language that is widely used in various fields, including web development, data analysis, artificial intelligence, and more. With its simple and easy-to-read syntax, Python has become a favorite among both new and experienced developers. In this article, weโ€™ll explore 10 insanely cool Python codes that youโ€™ll want to copy and paste right away to enhance your projects.
๐ŸŒ
Python.org
discuss.python.org โ€บ python help
Free recommended code sharing sites? - Python Help - Discussions on Python.org
February 16, 2024 - Iโ€™m fairly new to Python, I still have not finished my first Python tutorial. Sometimes itโ€™s easier to share longer code (50+ lines) on a code sharing website. Besides pastebin.com, what are recommended code sharing siteโ€ฆ
๐ŸŒ
CodeRivers
coderivers.org โ€บ blog โ€บ text-code-to-copy-and-paste-into-python
Working with Text Code to Copy and Paste into Python - CodeRivers
February 22, 2026 - Just open the relevant Python file, place the cursor where you want to insert the code, and paste it. IDEs often have features to help with code formatting and error detection. Indentation: Python uses indentation to define code blocks. When copying and pasting code, make sure the indentation is correct.
๐ŸŒ
Medium
medium.com โ€บ @zhongwei2049 โ€บ 8-delightful-python-scripts-to-brighten-your-day-5908c1761905
8 Delightful Python Scripts to Brighten Your Day | by Zhongwei | Medium
July 30, 2023 - 8 Delightful Python Scripts to Brighten Your Day As programmers, we regularly tackle coding challenges that demand sophisticated solutions beyond basic Python syntax. Copy-pasting snippets from โ€ฆ
๐ŸŒ
Normngyn
normngyn.com โ€บ python โ€บ how-to-copypasterun-codes
Norm's Portal - How to Copy/Paste/Run Codes
Check the "Simple Copy-and-Paste Codes" tab at the top of my website. Click Learning State Capitals. There you can highlight it to copy and paste it to Python. You can also edit the codes for your other learning needs! ... This site uses cookies from Google to deliver its services and to analyze traffic.
๐ŸŒ
Hackr
hackr.io โ€บ home โ€บ articles โ€บ projects
Top 40 Python Projects for Programmers (Beginner to Advanced)
February 19, 2026 - Explore 40+ hands-on Python projects, from beginner-friendly automation to professional portfolio applications, with step-by-step tutorials and video walkthroughs.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_lists_copy.asp
Python - Copy Lists
W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.
๐ŸŒ
Python.org
discuss.python.org โ€บ python help
Copy and Paste Files - Command - Python Help - Discussions on Python.org
June 24, 2024 - Good night people, I have a problem, I used the following code to copy and paste files from one folder to another import os import time import shutil origem = r"C:\Program Files\Corel\CorelDRAW Graphics Suite 2022\Programs64\Pasta2" destino = r"C:\Program Files\Corel\CorelDRAW Graphics Suite 2022\Programs64\Pasta1" def copy_files(origem, destino): os.makedirs(destino, exist_ok=True) for item in os.listdir(origem): origem_arquivo = os.path.join(origem, item) destino_ar...
๐ŸŒ
CodeConvert AI
codeconvert.ai โ€บ home โ€บ ai code generator โ€บ python code generator
Free Python Code Generator - AI-Powered | CodeConvert AI
Free AI Code Generator for writing Python code. Describe what you need, get working Python code instantly. No signup required.