2016-07-22 76 views
1

我试图在第二个Tkinter窗口中显示标签内的图像。 在我的主窗口(窗口)中,图像显示完美,但是当我编写出现在第二个窗口(根)内部的相同代码时,代码将执行,但看不到图像,只能看到空白区域。标签中的图像不出现在辅助窗口中(tkinter)

任何帮助将不胜感激!

这里是我的相关代码:

# Create a variable assigned to the location of the main image, and then change its proportions (the higher the number/s, the smaller) 
finance_news_image1 = PhotoImage(file = 'C:\\Users\\user\\Projects\\project\\x\\y\\z\\finance news.gif') 
finance_news_image2 = finance_news_image1.subsample(1, 1) 

# Create a variable for the main image of the menu, and define its placement within the grid 
main_photo = Label(root, image = finance_news_image2) 
root.main_photo = main_photo 
main_photo.grid(row = 4, column = 0) 

回答

1

您错误地保持参照图像。这意味着你需要改变这一行:

root.main_photo = main_photo 

要:

main_photo.image = finance_news_image2 
+1

非常感谢您!它现在可以工作,并且您的时间非常感谢。 – Nick