0

I am pretty new to python and tkinter and have been creating an app that will show me today's information, such as weather and time. I have a background image created by a canvas, and I have text on a label on the canvas, but I do not know how to see the canvas through the label.

I have attached what I have now and what I would like to see (made in paint), as well as the code that I have right now.

I keep seeing the -alpha widget and -transparentcolor widget being used but this goes straight through to the applications behind my tkinter window. I havent found a way to make either of these work, but I might be missing something.

Any ideas?

The code:

from tkinter import *
from time import strftime

HEIGHT = 1080
WIDTH = 1920

def time():
    clock = (strftime("%B"+" "+"%d"+" "+"%X"))
    label.config(text=clock)
    label.after(1000, time)

root = Tk()
root.title('App')
bg = PhotoImage(file="wallpaper.png")

canvas = Label(root, height=HEIGHT, width=WIDTH, image = bg)
canvas.pack()

label = Label(canvas, anchor='center', bg='black', fg='white',font=('Courier 45 bold'))
label.place(relx=0.05, rely=0.05, relwidth=0.4,relheight=0.2)
time()

root.mainloop()

What it currently looks like

What I would like it to look like

  • i think its the same problem: https://stackoverflow.com/questions/10461045/python-tkinter-label-background-transparent – Aru Jun 01 '21 at 16:47

1 Answers1

0

the -alpha method is to set your whole window to transperent. from 0% - 100%. With -transparent you can make parts of your window transperent. Maybe this example helps you a little bit:

from tkinter import *

root = Tk()
root.geometry("600x550")
root.attributes("-transparent", "red")                  # set your color, which should be transperent to the window attributes

frame1 = Frame(root, bg="black")
frame1.pack(fill="both", expand="yes")

frame2 = Frame(frame1, bg="red")                        # in the root attributes the color is set to red, if
frame2.pack(ipady=150, ipadx=150, pady=100)             # if you make another widget in red, this will be whole over
                                                        # over your window transparent
mainloop()
bangKok
  • 332
  • 2
  • 13