首页 > 解决方案 > 努力让图像出现在我基于 Tkinter 的程序的其他元素后面

问题描述

全新的编程,这是我第一个用任何语言编写的真正项目。

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

我不知道如何将图像移到后面层,不确定这是否是您提出这样一个问题的方式。

这是它当前的显示方式,您可以看到图像与所有内容重叠。

目前看起来如何

目前看起来如何

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

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)

标签: pythonpython-3.ximagetkinter

解决方案


推荐阅读