Python Tkinter-Label-hintergrund transparent
Ich habe ein Fenster mit einem label wie meinem Bild. Ich Tat dies, weil ich wollte ein Bild im hintergrund. Aber jetzt im Probleme mit den anderen Etiketten die ich verwendet habe. Die anderen labels, die ich früher eigentlich beschriftet die Dinge, die dont haben einen transparenten hintergrund. Gibt es eine Möglichkeit, um den hintergrund der labels transparent?
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()
Du musst angemeldet sein, um einen Kommentar abzugeben.
Ich glaube nicht, dass es unterstützt wird mit transparentem hintergrund in Tk... haben Sie etwas dagegen, setzen Sie Ihren code? Helfen könnte.
ich denke, dass es helfen kann, alle in schwarz transparent
root.wm_attributes('-transparentcolor', root['bg'])
zu machen, die Standard Farbe transparent.Wenn Sie mit Bildern arbeiten und putting text auf Ihnen, der bequemste Weg ist - denke ich - mit
Canvas
widget.tkinter Canvas
widget hat Methoden wie.create_image(x, y, image=image, options)
und.create_text(x, y, text="Some text", options)
.