简体   繁体   中英

(Python - Tkinter) During a function, using an image as second window background

So I've looked around at forums and video tutorials but I can't seem to solve the problem I'm having. Basically, I'm creating a GUI with multiple windows. When trying to set up my second window, I attempt to set an image as the background using the following code;

def openMusicPage():                                                               1
    MusicPage = Tk()                                                               2
    MusicPage.title('Now This Is Epic: Top Music Chart')                           3
    MusicPage.configure(width = 800, height = 505)                                 4

    # Background`enter code here`
    MusicBackground = PhotoImage(file="MusicBackground.gif")                       5   
    MusicBackground_label = Label(MusicPage, image = MusicBackground)              6
    MusicBackground_label.image=MusicBackground                                    7
    MusicBackground_label.place(x=0, y=0)                                          8

The error occurs on the 6th line saying the image doesn't exist. On other forums and videos, I've seen suggestions to add the 7th line to fix this issue by referencing the image again. However, this hasn't helped and I continue to receive the error. Any suggestions as to how I could solve this issue? Noting, I am only able to use Tkinter for this assignment.

Thanks in advance!

Only use one instance of Tk() . For additional windows use Toplevel() . Change that and it works just fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM