python中image显示图片,在Python中使用PhotoImage在Tkinter中显示图像

  • Post author:
  • Post category:python


我试图创建一个有主菜单和设置菜单的应用程序。我想为每一个设置背景。但我从设置菜单开始。我收到一个错误声明:

_tkinter.TclError: image “pyimage1” doesn’t exist。

我做错什么了?在from tkinter import *

from tkinter.ttk import *

install_directory = ‘…’

# ***********************************MAIN MENU*****************************************************

def root():

# ~~~Defines window~~~

main_window = Tk()

main_window.iconbitmap(install_directory + r’\resources\icons\logo.ico’) # Changes the icon for window

main_window.title(‘Auto Transfer’) # Changes window name

main_window.geometry(“300×200”)

# ~~Adds a background~~~

background = PhotoImage(file=install_directory + r’\resources\backgrounds\stardust.gif’)

label = Label(main_window, image=background)

label.pack()

# ~~~Menu Bar~~~</