Ich habe herausgefunden, wie man ein Bild für einen Button bekommt, der auf einem Label steht () Ich denke, ich mache es vielleicht auf langatmige Weise, weil ich PIL nicht installieren kann mein Mac aus irgendeinem Grund). Wie auch immer, es funktioniert bis zu einem gewissen Grad - das Problem, das ich habe, ist das Hinzufügen von Leerraum auf beiden Seiten, und dann zeigt das Bild selbst keinen transparenten Hintergrund. Tkinter - Button Image Transparenter Hintergrund
Der Code ich verwende ist wie folgt:
from tkinter import *
#from PIL import Image
root = Tk()
#Removes the title bar and places over mac top bar
root.tk.call("::tk::unsupported::MacWindowStyle", "style", root._w, "plain", "none")
# Makes the app full screen
#root.wm_attributes('-fullscreen', 1)
root.geometry('{}x{}'.format(480, 320))
#root.attributes('-topmost', True)
def quitApp():
# mlabel = Label (root, text = 'Close').pack()
root.destroy()
background_img = PhotoImage(file="images/bg.gif")
scanBtn_img = PhotoImage(file="images/scanBtn.gif")
background = Label(root,
compound = CENTER,
quitButton = Button(image=scanBtn_img, command = quitApp).pack(),
image = background_img).pack(side="right")
background.image = background_img # keep a reference!
root.mainloop()
Sie sicher sind Sie auf python 2.7 sind, weil Sie tkinter in Klein wie python 3. –