标签中的图像未出现在辅助窗口中(tkinter)

时间:2016-07-22 12:44:28

标签: python python-3.x 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 个答案:

答案 0 :(得分:1)

您错误地保留了对图像的引用。这意味着您需要更改此行:

root.main_photo = main_photo

要:

main_photo.image = finance_news_image2