我有一个带有标签的窗口作为我的框架。我这样做是因为我想在后台拍摄一张照片。但是现在我遇到了我用过的其他标签的问题。我用来实际标记的其他标签没有透明的背景。有没有办法让这些标签的背景透明?
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()
答案 0 :(得分:5)
我认为它可以提供帮助,所有黑色都是透明的
root.wm_attributes('-transparentcolor','black')
答案 1 :(得分:2)
我不认为Tk中的透明背景支持它...你介意提出你的代码吗?可能有帮助。
答案 2 :(得分:0)
如果您要处理图像并将文本放置在图像上,最方便的方法是-我认为-使用Canvas
小部件。
tkinter Canvas
小部件的方法分别为.create_image(x, y, image=image, options)
和.create_text(x, y, text="Some text", options)
。
答案 3 :(得分:0)
使用此:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<receiver
android:name=".BootReceiver"
android:enabled="true"
android:exported="true"
android:label="BootReceiver"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
如果使用public class BootReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
Intent i = new Intent(context, MainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
}
,则可以在第7行中进行更改
祝你好运:)