-4

これは私のコードです:

import tkinter as tk
win=tk.Tk()
class loadfileclass():
    filenamevar=''
    data=''
    try:
        filenamevar=tk.StringVar()
        fname=filenamevar.get()
        filenamevar.set("")
        mainfile=open(str(fname),"rb")
        data=mainfile.read()
        data=data.split("##########")
    except:
        pass

tk.Label(text='Filename: ').pack()
tk.Entry(textvariable=loadfileclass.filenamevar).pack()
tk.Button(text='Load',command=loadfileclass).pack()
data=loadfileclass.data
for i in data:
    def fun():
        global photo,data
        data.replace("##########","\n")
        fd=data.split("==========")
        photo=Tkinter.PhotoImage(file=fd[1])
        tk.Label(fd[0],image=photo).pack()
    fun()
win.mainloop()

画像やテキストでさえ、ラベルは表示されません。

入力に入力した名前のファイルの内容は次のとおりです。

画像

==========
(opened image in notepad and copy pasted it here)
##########
IMAGE
==========
(opened image in notepad and copy pasted it here again)
##########

それを修正する方法は?

4

1 に答える 1