我正在尝试将图像添加到我的Tkinter GUI中。但是我一直收到错误,特别是我的图像没有'read'属性。我已经用TIF,GIF和PNG格式的文件尝试过此操作,但似乎都无法正常工作。我已经检查过,其他似乎在添加png格式的图像时没有问题。我觉得问题很明显,但我很想念。
import tkinter as tk
from PIL import ImageTk, Image
class Window(tk.Frame):
def __init__(self, master=None):
tk.Frame.__init__(self, master)
self.master = master
self.init_window()
def init_window(self):
self.master.title("Lifespan Data Analyser")
self.pack(fill=tk.BOTH, expand=1)
path = Image.open('I:/python_work/TemplateRack_GUI.tif')
img = ImageTk.PhotoImage(file = path) #problem is here I think
panel = tk.Label(root, image = img)
panel.pack(side = "bottom", fill = "both", expand = "yes")
panel.image=img
root = tk.Tk()
root.geometry("400x300")
app = Window(root)
root.mainloop()
收到此属性错误:
AttributeError:'TiffImageFile'对象没有属性'read'
AttributeError:'JpegImageFile'对象没有属性'read'
答案 0 :(得分:0)
尝试:
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
<tr>
<td class="cell1">1</td>
<td class="cell2">111</td>
<td class="cell3">2018-12-22</td>
<td class="cell4">Apples</td>
<td class="liga">France</td>
<td>
<select data-select="newcell1" class="cell-select">
<option value="" selected="">Select one</option>
<option value="1.4">A</option>
<option value="2.3">B</option>
<option value="3.2">C</option>
<option value="1.5">D</option>
</select>
</td>
</tr>
<tr>
<td class="cell1">2</td>
<td class="cell2">222</td>
<td class="cell3">2018-12-23</td>
<td class="cell4">Oranges</td>
<td class="liga">Austria</td>
<td>
<select data-select="newcell2" class="cell-select">
<option value="" selected="">Select one</option>
<option value="1.1">X</option>
<option value="4.3">Y</option>
<option value="2.2">Z</option>
<option value="3.5">W</option>
</select>
</td>
</tr>
<tr>
<td class="cell1">3</td>
<td class="cell2">333</td>
<td class="cell3">2018-12-24</td>
<td class="cell4">Bananas</td>
<td class="liga">Germany</td>
<td>
<select data-select="newcell3" class="cell-select">
<option value="" selected="">Select one</option>
<option value="2.1">L</option>
<option value="3.5">M</option>
<option value="4.1">N</option>
<option value="2.2">Q</option>
</select>
</td>
</tr>
</table>
<table class="result">
<tr class="newcell1">
<td></td>
<td></td>
<td></td>
</tr>
<tr class="newcell2">
<td></td>
<td></td>
<td></td>
</tr>
<tr class="newcell3">
<td></td>
<td></td>
<td></td>
</tr>
</table>
<table>
<tr>
<td class="">111</td>
<td class="">Apples</td>
<td class="">1.4</td>
</tr>
<tr>
<td class="">222</td>
<td class="">Oranges</td>
<td class="">4.3</td>
</tr>
<tr>
<td class="">333</td>
<td class="">Bananas</td>
<td class="">4.1</td>
</tr>
</table>
未打开 进行此更改后,您的代码效果很好,请尝试使用另一个tif