2012-05-05 136 views
0

我有一個標籤作爲框架的窗口。我這樣做是因爲我想要一個背景圖像。但現在我遇到了我用過的其他唱片公司的麻煩。我用來標記事物的其他標籤沒有透明背景。有沒有辦法讓這些標籤的背景透明?Python Tkinter標籤背景透明

import Tkinter as tk 

root = tk.Tk() 
root.title('background image') 

image1 = Tk.PhotoImage(file='image_name.gif') 

# get the image size 
w = image1.width() 
h = image1.height() 

# make the root window the size of the image 
root.geometry("%dx%d" % (w, h)) 

# root has no image argument, so use a label as a panel 
panel1 = tk.Label(root, image=image1) 
panel1.pack(side='top', fill='both', expand='yes') 

# put a button/label on the image panel to test it 
label1 = tk.Label(panel1, text='here i am') 
label1.pack(side=Top) 

button2 = tk.Button(panel1, text='button2') 
button2.pack(side='top') 

# start the event loop 
root.mainloop() 

回答

2

我不認爲它在Tk中被透明背景支持......你介意放置你的代碼嗎?可能有幫助。

+0

我也這麼認爲。我也想這樣做。 – User

5

我認爲它可以幫助,全黑將是透明的

root.wm_attributes('-transparentcolor','black') 
+1

使用'root.wm_attributes(' - transparentcolor',root ['bg'])'使默認顏色透明。 – Nae