Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

advanced python code copy and paste

# CopyAndPaste.py

# This program is designed to read a GIF file, display its image on the screen, allows the user to
# select a rectangular portion of the image to copy and paste, and then save the result as a new GIF file

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 = PhotoImage(file="picture.gif")
    yaxis(event)
    canvas.create_rectangle(x1,y1,x2,y2)
    for x in range(x1, x2):
        for y in range(y1, y2):
            r,g,b = getRGB(photo, x, y)
            newImage(r, g, b, x, y)

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

def newImage(r, g, b, x, y):
    picture = PhotoImage(width=x, height=y)
    picture.put("#%02x%02x%02x" % (r,g,b), (x,y))
    picture.write('new_image.gif', format='gif')

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)

root.mainloop()
Comment

PREVIOUS NEXT
Code Example
Python :: get text from heatmap 
Python :: percentile of a score python 
Python :: python locateonscreen method 
Python :: Python NumPy insert Function Example Using insertion at different points 
Python :: Python NumPy hsplit Function 
Python :: creating a variable bound to a set python 
Python :: if statment with logical or operator for multiple varaibles 
Python :: model compile keras 
Python :: python interpreter after running a python file 
Python :: NumPy rot90 Example Rotating Twice 
Python :: else clause in for loop python 
Python :: colorbar over two axes 
Python :: Convertion of number into binary using NumPy binary_repr 
Python :: Break up long line of code to span over several lines 
Python :: list of pdf download python selenium 
Python :: python list and numpy array 
Python :: call a Python range() using range(start, stop) 
Python :: knn compute_distances_two_loop 
Python :: python get dataframe vlaues where cell is higher than 
Python :: how to create function python 
Python :: changing labels of facetgrid 
Python :: ignore exception decorator 
Python :: Flask error: werkzeug.routing.BuildError 
Python :: how to import grades into a text file in python 
Python :: clear notebook output 
Python :: plt datas use left and right yaxes 
Python :: how to insert a character into a string in python 
Python :: sumy library 
Python :: python list of datetimes as type string 
Python :: plt.axes muktiple plots 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =