如何在顶级窗口的tkinter上添加图片背景?

时间:2019-03-14 16:11:08

标签: python tkinter tkinter-canvas tkinter-layout

我找到了用于背景图片的代码,该代码在我的主窗口上非常有用:

C = Canvas(window, bg="blue", height=250, width=300)
filename = PhotoImage(file = "C:\\file_address\\background.png")
background_label = Label(window, image=filename)
background_label.place(x=0, y=0, relwidth=1, relheight=1)

C.grid(row=0, column=0, rowspan=5, columnspan=3)

但是,当我在Toplevel()窗口上使用它时,它根本没有显示-我只剩下灰色背景。它显示的唯一方式是当我使用C.pack()时,但是我的所有小部件都没有显示。我曾尝试过使用C.lift()和C.lower(),但似乎都无法按我的意愿进行。

1 个答案:

答案 0 :(得分:0)

正在收集垃圾,请参考图片

       //Create a new instance of Firefox Browser
       WebDriver driver = new FirefoxDriver();

       //Open the URL in firefox browser
       driver.get("https://www.google.co.in/");

       //Maximize the Browser window
       driver.manage().window().maximize();

       //Get the current page URL and store the value in variable 'str'
       String str = driver.getCurrentUrl();

       //Print the value of variable in the console
       System.out.println("The current URL is " + str);
    System.out.print("Hello World");
} }

这样做会在您打开C = Canvas(window, bg="blue", height=250, width=300) filename = PhotoImage(file = "C:\\file_address\\background.png") background_label = Label(window, image=filename) background_label.place(x=0, y=0, relwidth=1, relheight=1) background_label.image = filename # reference to the image C.grid(row=0, column=0, rowspan=5, columnspan=3)

时显示图像