努力使图像出现在基于Tkinter的程序的其他元素后面

时间:2019-02-11 17:39:55

标签: python python-3.x image tkinter

编程的新手,这是我用任何语言编写的第一个实际项目。

我目前正在为程序编写界面,我想在后面,现在,将来出现在顶部的按钮,文本框和其他元素后面显示图像。

我不知道如何将图像移至后层,不确定是否可以用这种方式表达这样的问题。

这是当前显示的样子,因为您可以看到图像覆盖了所有内容。

目前的样子

How it looks at the moment

到目前为止,这是我的代码:

from tkinter import *
from tkinter import ttk
from PIL import Image, ImageTk, ImageFont, ImageDraw

import tkinter as tk
import subprocess


#wifi scanning into file command
savename = "net.txt"


def wifi():
        f= open(savename,"w+")
        subprocess.run("wifi scan>"+ savename, shell=True, check=True)

def statustext(): #text that appears when save button is pressed
    savestatus = Label(root, text="Scanning and saving complete")
    savestatus.grid(row=6, column=3)


def hacktext():
        hackstatus= Label(root, text="Not Done Yet")
        hackstatus.grid(row=12, column=3)

def readfile():
        f= open(savename,"r")
        subprocess.run("leafpad " +savename, shell=True, check=True)

def readtext():
        openstatus= Label(root, text="Opening in Leafpad...")
        openstatus.grid(row=15, column=3)


def hackbut():
        hackspac = Label(root)
        hackspac.grid(row=12)
        hackbutton = Button(text="Hack Password", command=lambda:[(),hacktext()])
        hackbutton.bind("<Button-1>")
        hackbutton.grid(row=14,column=3)

def textbut():
        textspac =Label(root)
        textspac.grid(row=15)
        textbutton = Button(text="Display Text File", command=lambda:[(),readtext(),readfile()])
        textbutton.grid(row=16,column=3)

root = Tk()



scanbutton = Button(text="Scan & Save", command=lambda:[wifi(),statustext(),hackbut(),textbut()])
scanbutton.bind("<Button-1>")
scanbutton.grid(row=11,column=3)
root.geometry ('320x240')

bg = PhotoImage(file="background.gif")
background_label = Label(root, image=bg)
background_label.grid(row=1,column=1)

0 个答案:

没有答案