2017-02-17 29 views
0
from tkinter import * 

root = Tk() 

coords=1017,474 
canvas = Canvas(root, width=1080, height=960) 
frame = Frame(root,width=1080, height=960) 

def cords(event): 
    print(event.x,event.y) 



def click(event): 
    canvas.create_line(event.x,event.y,coords) 

canvas.bind('<B1-Motion>',click) 
canvas.bind('<Button-1>',cords) 


photo=PhotoImage('images.png') 
label=Label(frame,image=photo) 
label.grid(column=60) 

frame.pack(side='right') 
canvas.pack(side='left') 
root.mainloop() 

我的問題是,當我運行這個代碼,我有的圖像將不會顯示在所有,但一切工作。如果有人能幫我找出哪些錯誤會有所幫助。我找不到其他問題。我的圖像不會顯示使用tkinter

+0

沒有上一次我的窗前,沒有現在的權利的大小每一件事的作品,但圖像不會出現 – Nerfbeard

+0

Tkinter的許多版本不支持巴紐。嘗試使用.gif並查看是否可以解決問題。 –

+0

不,它仍然不起作用 – Nerfbeard

回答

0

必須提供的文件作爲file關鍵字參數的值。通過不指定file=,第一個參數被用作圖像的內部名稱。

photo=PhotoImage(file='images.png') 

稍微更多的信息在這個答案:https://stackoverflow.com/a/28010236/7432

0

我會嘗試這些:

photo=PhotoImage(file = 'images.png') 
label.config(image = photo) 
+0

當回答代碼塊中的代碼格式很重要時,可以通過標記文本並按{}符號或在每行之前添加4個空格來完成。另外,一個簡短的解釋將是非常有益的。 –

+0

好吧,我會盡力在將來做到這一點。謝謝。 – FlawlessData