1
我的問題是如何使用我將在稍後用askopenfilename()選擇的文件,例如將它放在畫布上? 我應該放什麼而不是「?」在「Im =?」 ? 謝謝! 對不起我非常初學者如何使用通過文件對話框選擇的文件?
import tkinter as tk
from tkinter import *
from tkinter.filedialog import *
root=tk.Tk()
root.geometry('1000x690')
root.title("Baccalauréat ISN 2017")
# # #
def Open_Image():
askopenfilename()
# # #
B13= Button(root, text='Open Image', height=5, width= 25, command = askopenfilename)
B13.grid(row=1, column=5, sticky= W + E)
Im = ?
# # #
Nim = Im.resize((int((Im.width*514)/Im.height), 514)) #maxsize =(821, 514) ---> size of the canvas 821-length; 514 -height
nshow = ImageTk.PhotoImage(Nim)
Can = tk.Canvas(root, background = 'blue')
Can.grid(row = 1, column = 0, rowspan = 6, columnspan = 5, sticky = W + E + N + S)
Cim = Can.create_image(0, 0, anchor = NW, image = nshow) # "0, 0" space between the picture and the borders
# # #
mainloop()
非常感謝你的回答,但是 我真的不明白它:我應該在哪裏從我的代碼中解決這個問題? 我真的是一個初學者,所以.. :) –