1
import tkinter as tk
from tkinter import *
import tkinter.messagebox as box

def dialog1():
    username=entry1.get()
    password = entry2.get()
    if (username == 'admin' and  password == 'secret'):
        window.destroy()
        window1=tk.Tk()
        window1.title('Dashboard')
        window1.configure(background="white")
        window1.geometry("1900x1200")
        photo2=PhotoImage(file='Project1d.png')
        w2=Label(window1,image=photo2)
        w2.pack()
        def Report():
            window1.destroy()
        frame1 = Frame(window1)
        frame1.pack(padx=100,pady = 19)
        btn1=Button(frame1,text='Reports',command=Report,font='Arial 10 
        bold',height=8,width=12,bg='cyan')
        btn1.pack(side=LEFT,pady=15,padx=10)
        btn2=Button(frame1,text='Reports1',command=Report,font='Arial 10 
        bold',height=8,width=12,bg='cyan')
        btn2.pack(side=LEFT,pady=15,padx=10)
        btn3=Button(frame1,text='Reports2',command=Report,font='Arial 10 
        bold',height=8,width=12,bg='cyan')
        btn3.pack(side=LEFT,pady=15,padx=10)
        btn4=Button(frame1,text='Reports3',command=Report,font='Arial 10 
        bold',height=8,width=12,bg='cyan')
        btn4.pack(side=LEFT,pady=15,padx=10)
window = tk.Tk()
window.title('Authentication!' )
window.configure(background="white")
window.geometry("1900x1200")
photo = PhotoImage(file = "Project1.png")
w = Label(window, image=photo)
w.pack(pady=15)
photo1 = PhotoImage(file = "Plant.png")
w1 = Label(window, image=photo1)
w1.pack(pady=15)
frame = Frame(window)
Label1 = Label(window,text = 'Username:',bg='white',font='Arial 10 bold')
Label1.pack(padx=15,pady= 5)
entry1 = Entry(window,bd =5)
entry1.pack(padx=15, pady=5)
Label2 = Label(window,text = 'Password: ',bg='white',font='Arial 10 bold')
Label2.pack(padx = 15,pady=5)
entry2 = Entry(window, bd=5,show='*')
entry2.pack(padx = 15,pady=5)
btn = Button(frame, text = 'Login',command = dialog1,font='Arial 10 bold')
btn.pack(side = RIGHT , padx =5)
frame.pack(padx=100,pady = 19)
Label(text='Copyright © 2016 UL Group. All Rights Reserved.',fg='black',bg='white',font='Arial 6 bold').pack(pady=15,side='bottom')
window.mainloop()

If I run the code, I get the following output.

Image is coming but not visible.

The image is coming but is not visible.

If I run only the if loop separately I am getting the image:

If i run only the if loop separately i'm getting the image

Can anyone please help me with the problem? I'm unable to decode the problem.

Dale K
  • 25,246
  • 15
  • 42
  • 71
  • 1
    This is probably due to using `Tk()` more than once in your code. Restructure it so that you only have one root instance. – Novel Mar 04 '19 at 05:01
  • 1
    Read [Why are multiple instances of Tk discouraged?](https://stackoverflow.com/questions/48045401/why-are-multiple-instances-of-tk-discouraged) and [Why does Tkinter image not show up if created in a function?](https://stackoverflow.com/a/16424553/7414759) – stovfl Mar 04 '19 at 07:34

0 Answers0