我需要帮助。我需要在genkeymenu函数中将图像背景显示到我新创建的帧中。但问题是,一旦创建了框架,图像背景似乎只会在第一个创建的框架中发生变化。我试图寻找解决方案,但没有任何作用。我可以问一下这是什么问题吗?
attr-accessor
答案 0 :(得分:0)
您指定要在顶层窗口中显示的所有窗口小部件,但不会为后台执行此操作。 background_label = Label(generatemenu, image=bg1)
import Tkinter as tk
from Tkinter import *
PIL import Image, ImageTk
def genkeymenu():
generatemenu = tk.Toplevel(mainmenu)
bg1 = ImageTk.PhotoImage(file="key2.jpg")
background_label = Label(generatemenu, image=bg1)# specify the window you it to appear.
background_label.place(x=0, y=0)
background_label.image = bg1
keynamelabel = Label(generatemenu, text="Enter your key name")
keynameEntry = Entry(generatemenu)
keynameButton = Button(generatemenu, text="Enter")
check1024= Checkbutton(generatemenu, text="1024 bit")
check2048= Checkbutton(generatemenu, text="2048 bit")
check4096= Checkbutton(generatemenu, text="4096 bit")
tk.background_label.grid(row=0)
keynamelabel.grid(row=0)
keynameEntry.grid(row=1)
keynameButton.grid(row=2)
check1024.grid(row=3, column=0)
check2048.grid(row=3, column=1)
check4096.grid(row=3, column=2)
generatemenu.title("Generate Key")
generatemenu.mainloop()
mainmenu = tk.Tk()
bg = ImageTk.PhotoImage(file="key.jpg")
background_label = Label(image=bg)
background_label.place(x=0, y=0)
genkeybutton = Button(mainmenu, text= "Generate Key Pair", fg="black",
command=genkeymenu)
encryptbutton = Button(mainmenu, text= "Encrypt your message", fg="black")
decryptbutton = Button(mainmenu, text= "Decrypt your message", fg="black")
background_label.grid(row=0)
genkeybutton.grid(row=0, column=0, sticky = N, rowspan=2)
encryptbutton.grid(row=0, column=0)
decryptbutton.grid(row=0, column=0, sticky=S)
mainmenu.title("RSA ENCRYPTION")
mainmenu.mainloop()