我已经研究出了如何为按钮设置图像,即定位在标签顶部(我想我可能会这样做,因为我无法安装PIL我的Mac出于某种原因)。无论如何,它在某种程度上应该起作用 - 我遇到的问题是它会在任何一方添加空白区域,然后图像本身不会显示其透明背景。Tkinter - 按钮图像透明背景
我使用的代码如下:
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()
你确定你在Python 2.7,因为你导入tkinter小写为python 3. –