0

I want to display a text or PNG image file on my laptop screen without taking up the window. To make it easier to understand, I have attached some example images below. I searched on Google and came across StackOverflow but unfortunately it's not what I need. Here's an example of a Stackoverflow post: link

and it can't close the TK window unless using Task Manager :(

Here is an example of what I need, thanks.

Initial: img 1

After running the program it will look like this:img 2

1 Answers1

1

This is the answer from here: https://stackoverflow.com/a/22105730/13293676, with certain undesirable lines commented out. In addition, to solve the "exit" problem, I have added a line that will cause the window to close when the text is clicked.

import tkinter as Tkinter, win32api, win32con, pywintypes, sys

label = Tkinter.Label(text='Text on the screen', font=('Times New Roman','80'), fg='black', bg='white')
label.master.overrideredirect(True)
label.master.geometry("+250+250")
label.master.lift()
label.master.wm_attributes("-topmost", True)
#label.master.wm_attributes("-disabled", True)
label.master.wm_attributes("-transparentcolor", "white")
# Exit if text label is clicked
label.bind("<Button-1>", lambda e:sys.exit())

# hWindow = pywintypes.HANDLE(int(label.master.frame(), 16))
# http://msdn.microsoft.com/en-us/library/windows/desktop/ff700543(v=vs.85).aspx
# The WS_EX_TRANSPARENT flag makes events (like mouse clicks) fall through the window.
#exStyle = win32con.WS_EX_COMPOSITED | win32con.WS_EX_LAYERED
#win32api.SetWindowLong(hWindow, win32con.GWL_EXSTYLE, exStyle)

label.pack()
label.mainloop()
TookieWookie
  • 372
  • 3
  • 11