我試圖將圖像應用於背景。隨着我的按鈕在給定的圖像(與他們的圖片)頂部。我嘗試了Canvas,PIL,但其中任何一個都不起作用,或者圖像超出了一切。有任何想法嗎? (再次對我的代碼的方向感到抱歉)。Python 3.X,無法獲得我的按鈕後面的背景圖像
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()
不要對你的代碼感到抱歉。 _修補你的code_。如果你不願意花幾分鐘格式化你的問題,爲什麼你會期望陌生人花時間去理解它?另外,請閱讀並遵循以下建議:[如何創建最小,完整和可驗證示例](http://stackoverflow.com/help/mcve)。如果您的問題出在按鈕和背景圖片上,那麼您將不需要13個按鈕來說明問題。 –