无法在tkinter窗口中获取背景图像(循环运行)

时间:2019-03-04 04:58:03

标签: python tkinter

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()

如果运行代码,则会得到以下输出。

Image is coming but not visible.

图像即将到来,但不可见。

如果我只运行if循环,我将得到图像:

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

有人可以帮助我解决这个问题吗?我无法解码问题。

0 个答案:

没有答案