0

Brand new to programming, this being my first real project written in any language.

I'm currently writing the interface for a program, and im wanting to display an image behind, buttons, text boxes and other elements that will appear now and in the future over the top.

I can't work out how to shift the image to the back layer, not sure if this is how you'd phrase such a question.

Here is what it currently appears as, as you can see the image overlaps everything.

How it looks at the moment

How it looks at the moment

Here is my code so far:

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)
martineau
  • 119,623
  • 25
  • 170
  • 301
Afro-Sam
  • 1
  • 1
  • Have you tried creating the image first, _before_ the other buttons? The z-order defaults to the order that widgets are created, so widgets created later will be higher than widgets created earlier. – Bryan Oakley Feb 11 '19 at 18:45
  • Just tried and sadly not Bryan, creating the image earlier doesn't seem to make any difference at all, thanks for the reply though. – Afro-Sam Feb 11 '19 at 19:18
  • Just seen a comment in this thread https://stackoverflow.com/questions/54637795/how-to-make-a-tkinter-canvas-rectangle-transparent about transparency, or rather no transparency below the top-level window. hth – Martin Zaske Feb 11 '19 at 21:27
  • Try changing `background_label.grid(...)` to `background_label.place(x=0, y=0)` and create the `background_label` first (i.e. before the `scanbutton`). – acw1668 Feb 12 '19 at 08:36
  • Perfect, thanks so much acw1668, that's exactly what i needed! – Afro-Sam Feb 18 '19 at 15:38

0 Answers0