从tkFileDialog.askopenfilename

时间:2016-02-22 22:04:03

标签: python tkinter python-imaging-library

我想让用户选择图像以粘贴徽标图像。弹出文件对话框,让您选择图像文件。徽标图像也会加载并调整大小。并制作新的图像文件。

我的问题在于打开所选的图像。当它到达“im = PIL.Image.open(img)”时,它给我一个IOError,上面写着“没有这样的文件或目录”。

import PIL
import os.path  
import PIL.Image  
from Tkinter import *
from Tkinter import Tk
from tkFileDialog import askopenfilename
import Tkinter, tkFileDialog

def logo():

    imgs = tkFileDialog.askopenfilename(parent=root, title='Choose files', multiple = True)
    logo = PIL.Image.open('logo.jpeg')
    logo_new = logo.resize((125, 100))
    newpath = r'C:\Users\Austin\Desktop\New Images' 
    if not os.path.exists(newpath):
        os.makedirs(newpath)
    for img in imgs:
        im = PIL.Image.open(img)
        width, height = im.size()
        im.paste(logo_new, ((width-125), (height-100)), mask=logo_new)
        im.save(newpath)

#GUI Code
root = Tk()
root.title("Ad Maker") #GUI title
root.geometry("250x250") #GUI size
app = Frame(root)
app.grid()
button1 = Button(app, text="Logo", command=logo)
button1.grid() #sets button for the logo function
button2 = Button(app, text = "Frame")
button2.grid() #sets button for the frame function
root.mainloop()

我知道这段代码可能并不是最好的,因为我对编程还很新,但是让logo()函数最终起作用的任何帮助都会非常感激。

0 个答案:

没有答案
相关问题