2017-05-25 71 views
0

我想,當我運行下面給出的代碼,沒有什麼haapens.Only一個布通和標籤創建圖像設置爲frame.However的背景設置圖像幀的Tkinter蟒蛇的背景

class StartPage(tk.Frame): 

    def __init__(self, parent, controller): 
     tk.Frame.__init__(self, parent,bg='#a1dbcd') 
     im = Image.open('ASL.jpg') 
     tkimage = ImageTk.PhotoImage(im) 
     myvar=yk.Label(self,image = tkimage) 
     myvar.place(relx=0.5, rely=0.735, anchor=CENTER) 



     label = tk.Label(self, text="Click Below To start numeral recognition",fg='black',bg='#a1dbcd') 
     label.config(width=45) 
     label.config(font=("Helvetica", 25)) 
     label.pack(pady=10,padx=10) 
     s = ttk.Style() 
     s.configure('my.TButton', font=('Helvetica', 25),fg="#a1adbcd",bg="#ff0000") 

     button = tk.Button(self, text="Numeral Recognition",fg='white',bg='#383a39', 
          command=A,height=2,width=50) 

     #button.size(height=50,width=50) 
     #button.configure(state = "normal", relief="raised", bg = "red") 
     button.config(width = 35) 
     button.grid(row=1,column=1) 
     button.pack() 

回答

1

你需要在某處保存對tkimage的引用(可能爲self.tkimage),以防函數返回時垃圾回收。僅僅有一個小部件使用的圖像不幸的是不足以保持對象的活着。

+0

現在標籤疊加圖像。如何顯示它是圖像的一部分? – Rock