所以这就是我正在使用的所有代码。我只是练习用askopenfilename()函数,那是我遇到这个问题的时候
from tkinter import *
from PIL import ImageTk,Image
import tkinter.messagebox as tmsg
import tkinter.filedialog as fd
def open_1():
name = fd.askopenfilename(initialdir="/",title="Select Files",filetypes=(("png File","*.png"),("All
Files","*.*")))
label_1 = Label(root,text = f"{name}",borderwidth = 2,relief="groove")
label_1.grid()
my_img = Image.open(f"{name}")
my_img_1 = ImageTk.PhotoImage(my_img)
label_2 = Label(root, image=my_img_1, borderwidth=2, relief="groove")
label_2.grid(row=1,column=0)
print(name)
root = Tk()
root.geometry("700x500")
root.title("File_Dialouge Test")
img = ImageTk.PhotoImage(Image.open("22.jpg"))
root.iconphoto(False,img)
def test():
print("It Works You Idoit")
def save():
fd.asksaveasfile()
def save_as():
pass
def exit():
pass
file = Menu(root)
file_1 = Menu(file,tearoff=False)
file_1.add_command(label="Open", command = open_1)
file_1.add_command(label="Save",command = save)
file_1.add_command(label="Save As",command = save_as)
file_1.add_command(label="Exit",command = exit)
root.config(menu=file)
file.add_cascade(label="FILE", menu = file_1)
root.mainloop()
最终输出在图像中: This is the final output I'm getting, only the image borders are visible instead of actual image