我已經研究出瞭如何爲按鈕設置圖像,即定位在標籤頂部(我想我可能會這樣做,因爲我無法安裝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. –