メイン メニューと設定メニューを持つアプリケーションを作成しようとしています。これらのそれぞれに背景を設定したいと思います。しかし、私は設定メニューから始めています。次のエラーが表示されます:
_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("300x200")
# ~~Adds a background~~~
background = PhotoImage(file=install_directory + r'\resources\backgrounds\stardust.gif')
label = Label(main_window, image=background)
label.pack()
# ~~~Menu Bar~~~
menubar = Menu(main_window) # Creates the menu bar
# ~~~File menu~~~
filemenu = Menu(menubar, tearoff=0)
filemenu.add_command(label="Quit", command=lambda: main_window.destroy()) # Exits the program
# ~~~Settings menu~~~
settingsmenu = Menu(menubar, tearoff=0)
settingsmenu.add_command(label="Change settings...", command=lambda: options(main_window))
# ~~~Add menus to bar~~~
menubar.add_cascade(label='File', menu=filemenu)
menubar.add_cascade(label='Settings', menu=settingsmenu)
# ~~Adds menu bar to the screen~~~
main_window.config(menu=menubar)
# ~~Adds 'RUN' button~~
# ~~~Runs window~~~
main_window.mainloop()
# *********************************OPTIONS MENU****************************************************
def options(main_window):
options_window = Toplevel()
options_window.iconbitmap(install_directory + r'\resources\icons\logo.ico') # Changes the icon for window
options_window.title('Settings') # Changes window name
options_window.geometry("720x480")
# ~~Adds a background~~~
background = PhotoImage(file=install_directory + r'\resources\backgrounds\stardust.gif')
label = Label(options_window, image=background)
label.pack()
# *******************************RUN APP**************************************************************
if __name__ == '__main__':
root()