2017-07-06 15 views
1

イメージをtkinterウィンドウに配置しようとしていて、何が原因であるのか不明確なエラーが発生しました。パスはコンピュータ上の場所の100%です。Image to Tkinter Window

import tkinter 

import os 

from PIL import ImageTk, Image 


#Actual window   
window = tkinter.Tk() 
window.geometry('400x400') 
window.title('Game') 
window.configure(bg = 'Indian red') 

#Pictures 
path = 'E:\Hack Things\python\amazonlogo' 
img = ImageTk.PhotoImage(Image.open(path)) 
panel = tk.Label(window, image = img) 
panel.pack(side = "bottom", fill = "both", expand = "yes") 

#Buttons 
start = tkinter.Button(text = 'Start', height = 5, width = 25, font = 
('Helvetica', 12)) 

start.place(relx = .5, rely = .25, anchor='c') 

options = tkinter.Button(text="Options") 
options.place(relx = .5, rely = .45, anchor='c') 

exitbutton = tkinter.Button(text = 'Exit Game', command = quit, height = 5, 
width = 15, fg = 'red') 
exitbutton.place(relx = .5, rely = .85, anchor='c') 

window.mainloop() 

私はあなたが(前に引用符をrを追加することによって)生の文字列を使用する必要があります。このエラーに

Traceback (most recent call last): 
    File "E:\Hack Things\python\start.py", line 16, in <module> 
    img = ImageTk.PhotoImage(Image.open(path)) 
    File "C:\Users\Ihas\AppData\Local\Programs\Python\Python36-32\lib\site- 
packages\PIL\Image.py", line 2477, in open 
    fp = builtins.open(filename, "rb") 
OSError: [Errno 22] Invalid argument: 'E:\\Hack Things\\python\x07mazonlogo' 

答えて

2

を取得しています。または、バックスラッシュをエスケープしてください(\の前に\を追加してください)。 \aは、「ASCIIベル(BEL)」という特別な意味を有するため、

path = r'E:\Hack Things\python\amazonlogo'