首页 > 解决方案 > Python - 在标签中加载图像

问题描述

我很难使用PAGE GUI Generator在标签中加载图像。下面是我的用户界面:

在此处输入图像描述

每次单击“浏览文档”按钮时,它都会调用一个open_file_dialog_function,下面是函数:

def open_file_dialog(self):

   self.filename = filedialog.askopenfilename(initialdir = "/", title = "Select A File", filetype =  (("jpeg", "*.jpg"), ("All Files", "*.*")))

   #Display Document Path
   self.label_document_path1 = ttk.Label(self.label_document_path, text = "")
   self.label_document_path1.grid(column = 1, row = 2)         
   self.label_document_path1.configure(text = self.filename)

   #Load Damaged Document
   load = Image.open(self.filename)
   render = ImageTk.PhotoImage(load) 

   self.label_input_document1 = ttk.Label(self.label_input_document, image = render)
   self.label_input_document1.grid(column = 1, row = 3)  
   self.label_input_document1.configure(image = render) 

每次执行该功能时,它只在假定的图像中显示白色。为什么?请帮我。

在此处输入图像描述

标签: pythonpython-3.xpython-2.7tkinter

解决方案


推荐阅读