Issue
I'm trying to apply an image to the background. With my buttons to be on top of given image (with their pictures). I attempted Canvas, PIL, but either of them aren't working or the image comes over everything. Any ideas? (AGAIN sorry for the orientation of my code).
from tkinter import *
import os
from PIL import Image, ImageTk
# create the main window and title
app = Tk()
app.title("Virtual Receptionist")
app.geometry("300x300")
app.configure(background="black")
# background images
label1 = Label(app, text="Please select a name from the Directory or press
Deliveries")
label1.place(x= 64, y = 22, height=135, width=20)
mainwindow = app
"""Define any items that will be utilized when the button(s) are pressed (Close Window, Bat files for calling, any additional options)"""
# Testing area
# closed the window commandlet#
def closewindow():
exit()
# call numbers listed in individual bat files for use when button is pressed (each bat will have it own number or extension)
def callOffice():
os.system("c:/netis/phone/callfile.bat")
def callOffice1():
os.system("c:/netis/phone/callfile.bat")
def callOffice2():
os.system("c:/netis/phone/callfile.bat")
def callOffice3():
os.system("c:/netis/phone/callfile.bat")
def callOffice4():
os.system("c:/netis/phone/callfile.bat")
def callOffice5():
os.system("c:/netis/phone/callfile.bat")
def callOffice6():
os.system("c:/netis/phone/callfile.bat")
def callOffice7():
os.system("c:/netis/phone/callfile.bat")
def callOffice8():
os.system("c:/netis/phone/callfile.bat")
def callOffice9():
os.system("c:/netis/phone/callfile.bat")
def callOffice10():
os.system("c:/netis/phone/callfile.bat")
def callOffice11():
os.system("c:/netis/phone/callfile.bat")
# images for the pictures that display over the buttons listed below
photo1=PhotoImage(file="image folder/customerimg1.png")
photo2=PhotoImage(file="image folder/customerimg2.png")
photo3=PhotoImage(file="image folder/customerimg3.png")
photo4=PhotoImage(file="image folder/customerimg4.png")
photo5=PhotoImage(file="image folder/customerimg5.png")
photo6=PhotoImage(file="image folder/customerimg6.png")
photo7=PhotoImage(file="image folder/customerimg7.png")
photo8=PhotoImage(file="image folder/customerimg8.png")
photo9=PhotoImage(file="image folder/customerimg9.png")
photo10=PhotoImage(file="image folder/customerimg10.png")
photo11=PhotoImage(file="image folder/customerimg11.png")
photo12=PhotoImage(file="image folder/customerimg12.png")
photoc=PhotoImage(file="image folder/close.png")
# creating the button schema for the extensions
button1 = Button(mainwindow, text="Close Window", command=closewindow,
image=photoc, bg='Dark Slate Gray')
button2 = Button(mainwindow, text="client name1", command=callOffice,
image=photo1, bg='Dark Slate Gray')
button3 = Button(mainwindow, text="client name2", command=callOffice1,
image=photo2, bg='Dark Slate Gray')
button4 = Button(mainwindow, text="client name3", command=callOffice2,
image=photo3, bg='Dark Slate Gray')
button5 = Button(mainwindow, text="client name4", command=callOffice3,
image=photo4, bg='Dark Slate Gray')
button6 = Button(mainwindow, text="client name5", command=callOffice4,
image=photo5, bg='Dark Slate Gray')
button7 = Button(mainwindow, text="client name6", command=callOffice5,
image=photo6, bg='Dark Slate Gray')
button8 = Button(mainwindow, text="client name7", command=callOffice6,
image=photo7, bg='Dark Slate Gray')
button9 = Button(mainwindow, text="client name8", command=callOffice7,
image=photo8, bg='Dark Slate Gray')
button10 = Button(mainwindow, text="client name9", command=callOffice8,
image=photo9, bg='Dark Slate Gray')
button11 = Button(mainwindow, text="client name10", command=callOffice9,
image=photo10, bg='Dark Slate Gray')
button12 = Button(mainwindow, text="client name11", command=callOffice10,
image=photo11, bg='Dark Slate Gray')
button13 = Button(mainwindow, text="client name12", command=callOffice11,
image=photo12, bg='Dark Slate Gray')
#Configs for the buttons Size(s):#
button1.config(image=photoc, width="155", height="150")
button2.config(image=photo1, width="155", height="150")
button3.config(image=photo2, width="155", height="150")
button4.config(image=photo3, width="155", height="150")
button5.config(image=photo4, width="155", height="150")
button6.config(image=photo5, width="155", height="150")
button7.config(image=photo6, width="155", height="150")
button8.config(image=photo7, width="155", height="150")
button9.config(image=photo8, width="155", height="150")
button10.config(image=photo9, width="155", height="150")
button11.config(image=photo10, width="155", height="150")
button12.config(image=photo11, width="155", height="150")
button13.config(image=photo12, width="155", height="150")
# Button Orentation within the window itself (calling to grid func)#
button1.grid(row=0, column=0)
button2.grid(row=2, column=4)
button3.grid(row=2, column=5)
button4.grid(row=2, column=6)
button5.grid(row=2, column=7)
button6.grid(row=2, column=8)
button7.grid(row=2, column=9)
button8.grid(row=4, column=4)
button9.grid(row=4, column=5)
button10.grid(row=4, column=6)
button11.grid(row=4, column=7)
button12.grid(row=4, column=8)
button13.grid(row=4, column=9)
app.mainloop()
Solution
To see the background text adjust the numbers in the line:
label1.place(x= 64, y = 22, height=135, width=20)
to numbers making the text no more hidden behind the button:
label1.place(x=200, y=22, height=20, width=400)
Another option is to use a large background image, so that you can see in any case the image behind the buttons:
mainwindow = app
filename = PhotoImage(file="/path/To/Background/image.png")
background_label = Label(app, image=filename)
background_label.place(x=0, y=0, relwidth=1, relheight=1)
For more about what is going on behind the scenes in tkinter put in the search box here on stackoverflow.com the terms "tkinter background image" - there is a lot of valuable information available on this subject.
Answered By - Claudio
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.