All pastes #798964 Raw Edit

Mine

public python v1 · immutable
#798964 ·published 2007-11-27 04:35 UTC
rendered paste body
from Tkinter import *import tkFileDialogfrom picture import *from PIL import ImageTkimport image_manipulationdef quit(window):    window.destroy()    def save_file(window):    photo = c_pic.save_pic.get_image()    filename = tkFileDialog.asksaveasfilename()    photo.save(filename + '.bmp')    #print photo    def open_file(windows):       pic = make_picture(pick_a_file())    photo = ImageTk.PhotoImage(pic.get_image())    c_pic.config(image=photo)    c_pic.config(width=photo.width())    c_pic.config(height=photo.height())    c_pic.image = photo    c_pic.save_pic = pic        frame2.pack()    frame2.config(bg='black')def callback():    print "called the callback!"def rotate_callback():    top = Toplevel()    top.minsize(width=100, height=100)    top.title("Rotate Image")    rotation1 = Label (top, text="cw")    rotation1.grid(row=1,column=0)    rotation2 = Label (top, text="ccw")    rotation2.grid(row=1,column=1)    rotation_degrees = StringVar()    rotation_degrees.set("left 90")    rotate_left(top, rotation_degrees)    rotate_right(top, rotation_degrees)def rotate_left(top, rotation_degrees):        degree_90_left = Radiobutton (top, text="90", variable=rotation_degrees, \                                  value="left 90")    degree_90_left.grid(row=2, column=0)    degree_180_left = Radiobutton (top, text="180", variable=rotation_degrees, \                             value="left 180")    degree_180_left.grid(row=3, column=0)    degree_270_left = Radiobutton (top, text="270", variable=rotation_degrees, \                                   value ="left 270")    degree_270_left.grid(row=4, column=0)        def rotate_right(top, rotation_degrees):    degree_90_right = Radiobutton (top, text="90", variable=rotation_degrees, \                                   value="right 90")    degree_90_right.grid(row=2, column=1)    degree_180_right = Radiobutton (top, text="180", variable=rotation_degrees, \                                   value="right 180")    degree_180_right.grid(row=3, column=1)    degree_270_right = Radiobutton (top, text="270", variable=rotation_degrees, \                                   value ="right 270")    degree_270_right.grid(row=4, column=1)    ok_button = Button (top, text="Ok", command=lambda: process_rotate \                        (rotation_degrees), padx=12)    ok_button.grid(row=5, column=1)def process_rotate(rotation_degrees):    rotate = rotation_degrees.get()    rotation = 0    if rotate == "left 90" or rotate == "right 270":        rotation = 90    elif rotate == "left 180" or rotate == "right 180":        rotation = 180    elif rotate == "right 90" or rotate == "left 270":        rotation = 270    pic = c_pic.save_pic.get_image()     new_pic = image_manipulation.rotate(pic, rotation)    photo = ImageTk.PhotoImage(new_pic.get_image())    c_pic.config(image=photo)    c_pic.config(width=photo.width())    c_pic.config(height=photo.height())    c_pic.image = photo    c_pic.save_pic = photo    #def :if __name__ == '__main__':    window = Tk()    window.minsize(580,640)    window.title("Image Tweak v1.0")    frame = Frame (window)    frame.pack(side=TOP, fill=X)        menubar = Menu(window)    filemenu = Menu(menubar)    open_command = lambda : open_file(window)    filemenu.add_command(label="Open", command=open_command)    save_command = lambda : save_file(window)    filemenu.add_command(label="Save", command=save_command)    quit_command = lambda : quit(window)    filemenu.add_command(label="Quit", command=quit_command)    menubar.add_cascade(label="File", menu=filemenu)            window.config(menu=menubar)        b1 = Button(frame, text="rotate", width=6, command=rotate_callback)    b1.pack(side=LEFT, padx=1, fill=BOTH, expand=1)    b2 = Button(frame, text="Grey Scale", width=6, command=callback)    b2.pack(side=LEFT, padx=1, fill=BOTH, expand=1)    b3 = Button(frame, text="Mirror Image", width=6, command=callback)    b3.pack(side=LEFT, padx=1, fill=BOTH, expand=1)    b4 = Button(frame, text="Remove RedEye", width=6, command=callback)    b4.pack(side=LEFT, padx=1, fill=BOTH, expand=1)    b5 = Button(frame, text="Crop", width=6, command=callback)    b5.pack(side=LEFT, padx=1, fill=BOTH, expand=1)    b6 = Button(frame, text="Resize", width=6, command=callback)    b6.pack(side=LEFT, padx=1, fill=BOTH, expand=1)    frame2 = Frame(window)    c_pic = Label(frame2, width=500, height=500,bg="black")    c_pic.pack()        scrollbar_y = Scrollbar (window)    scrollbar_y.pack(side=RIGHT, fill=Y)    scrollbar_x = Scrollbar (window)    scrollbar_x.pack(side=BOTTOM, fill=X)        scrollbar_x.config(orient=HORIZONTAL)    window.config(menu=menubar)        window.mainloop()