tkinter - Python 3.X, can't get a background image behind my buttons -
i'm trying apply image background. buttons on top of given image (with pictures). attempted canvas, pil, either of them aren't working or image comes on everything. ideas? (again sorry orientation of code).
from tkinter import * import os pil import image, imagetk # create main window , title app = tk() app.title("virtual receptionist") app.geometry("300x300") app.configure(background="black") # background images label1 = label(app, text="please select name directory or press deliveries") label1.place(x= 64, y = 22, height=135, width=20) mainwindow = app """define items utilized when button(s) pressed (close window, bat files calling, additional options)""" # testing area # closed window commandlet# def closewindow(): exit() # call numbers listed in individual bat files use when button pressed (each bat have 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 pictures display on 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 button schema 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 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 window (calling 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()
to see background text adjust numbers in line:
label1.place(x= 64, y = 22, height=135, width=20) to numbers making text no more hidden behind button:
label1.place(x=200, y=22, height=20, width=400) another option use large background image, can see in case image behind 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 going on behind scenes in tkinter put in search box here on stackoverflow.com terms "tkinter background image" - there lot of valuable information available on subject.
have fun :) coding .
Comments
Post a Comment