我想做的是;
1-选择一张图片并将其保存在新目录中,方法是给它一个“型号为”和“股票代码”。
2-然后用这个新名称在屏幕上显示图片。
第一步是成功的。然而,当我邀请他进入画面时,即使为他腾出空间,也无法得到照片。我做错了什么.. !!
提前感谢您的帮助。 这是我的代码。
from tkinter import filedialog
import shutil
import os
from tkinter import *
from PIL import ImageTk, Image
model_no = "Y101"
stock_code = "Y101BLACK"
pencere = Tk()
Lframe = LabelFrame(pencere, text=" Resim ", bg="#eeeeee")
Lframe.grid(row=0, column=6, rowspan=2, columnspan=3, sticky='wens', pady=5, padx=5)
def resimal():
filename = filedialog.askopenfilename(initialdir = "C:\\Python34\\build",title = "Select file",
filetypes = (("jpeg files","*.jpg"),("all files","*.*")))
print("filename: ", filename)
fln = filename.split("/")[-1]
print("fln", fln)
backup_directory = ["{}\\Documents\\Ortak Yedek\\{}".format(os.path.expanduser('~'), model_no)]
try:
os.makedirs(os.sep.join(backup_directory)) # Indexing from List to Backup
except OSError:
pass
if filename:
shutil.copy2(filename, os.sep.join(backup_directory)) # Backup / import directories
else:
return
try:
os.rename("{}\\{}".format(os.sep.join(backup_directory), fln),
"{}\\{}.jpg".format(os.sep.join(backup_directory), stock_code))
except FileExistsError:
print("error")
backup_directory = ["{}\\Documents\\Ortak Yedek\\{}".format(os.path.expanduser('~'), model_no)]
picture = "{}\\{}.jpg".format(os.sep.join(backup_directory), stock_code)
img = ImageTk.PhotoImage(Image.open(picture))
panel = Label(Lframe, image=img)
panel.grid(row=1, column=0)
take_picture = Button(Lframe, text="Take Picture", width=10, command=resimal)
take_picture.grid(row=0, column=0, sticky='we')
mainloop()