-1
def Login():
   global W_Menu
   W_Menu = Tk()
   W_Menu.geometry('195x300+600+200')
   W_Menu.title("NSS DB")
   A0 = Canvas(W_Menu, width='160', height='160')
   A0.pack()
   img = PhotoImage(file="nsslogo.gif")
   A0.create_image(0,0, image=img)
   A3 = Label(W_Menu, text = "Username")
   A3.pack()
   A4 = Entry(W_Menu, bd = 3)
   A4.pack()
   A5 = Label(W_Menu, text = "Password")
   A5.pack()
   A6 = Entry(W_Menu, show = "*", bd = 3)
   A6.pack()
   A7 = tkinter.Button(W_Menu, text = "Log In", command = Reaction)
   A7.pack()
   A8 = tkinter.Button(W_Menu, text = "Register", command = RegisterMenu)
   A8.pack()

I have looked at my friend's code for adding an image to a canvas (which works, image shows correctly) and pretty much copied it word for word but just replaced the filename. For some reason the image does not show up. The window shows up, alongside all of the labels and buttons and I get no errors. The canvas is there but the image simply does not want to show.

'nsslogo.gif' is in exactly the same directory as the code so I do not understand why it doesn't work. Help?

user3112327
  • 275
  • 3
  • 6
  • 14
  • Variations of this question have been asked and answered many times on this site. Did you do a search before asking the question? Maybe we can improve the original questions so they are easier to find. – Bryan Oakley Sep 19 '14 at 14:14

1 Answers1

1

Make the PhotoImage objects not to be garbage collected.

The simplest way to do it is maybe declaring the variable as a global.

def Login():
    global W_Menu
    global img  # <----------
    W_Menu = Tk()
    ...
falsetru
  • 357,413
  • 63
  • 732
  • 636