python-3.xtkinterpysimpleguieasygui

How to display TEXT ONLY (transparent background, with no menu bar or buttons) on screen using Python?


I have been looking everywhere for this kind of simple solution and I'm still coming up short.

All I want to do is simply splash some text only onto the screen, without a background or using a "message box" that has a menu bar/buttons with it. Just text, that's all. Maybe with a way to set a color for the font as well as I want the text to be a light gray. Using Windows 10 and Python 3.8+.

I've looked at easygui (message box, uses buttons), PySimpleGUI (best option so far, shown below, but defaults to a white background), Tkinter and pygame (but I have no clue how to set up what I'm looking for with those packages.

This is what I have using PySimpleGui, would love for this to be a transparent background if possible!

def popup_message(message):
    sg.popup(str(message),
                title = None,
                button_color = 'white',
                background_color = None,
                text_color = 'grey85',#'light gray',
                button_type = 5,
                auto_close = True,
                auto_close_duration = 20,
                custom_text = (None, None),
                non_blocking = False,
                icon = None,
                line_width = None,
                font = None,
                no_titlebar = True,
                grab_anywhere = True,
                keep_on_top = True,
                location = (None, None),
                relative_location = (250, 250),
                any_key_closes = True,
                image = None,
                modal = True)

UPDATE

This is the closest thing I've got with using Tkinter. Problem now is the menu bar is still visible, and using the Label class results in a solid background. HOW CAN I ONLY SHOW TEXT ON SCREEN IN PYTHON!? I'm not even sure I'm going about this the right way, but seems like a pretty basic idea?

# Import the Tkinter Library
from tkinter import *

# Create an instance of Tkinter Frame
root = Tk()

# Create a Label to print some text
label = Label(root, text="This is a New Line Text", font= ('Helvetica 14 bold'), foreground= "red3")
label.pack()

# Create a transparent window
root.wm_attributes('-transparentcolor','#add123')

# Set the geometry of window
root.geometry("700x350")

# Add a background color to the Main Window
root.config(bg = '#add123')

root.mainloop()

enter image description here


Solution

  • Transparent background of Text in popupis not supported.

    New popup function required and defined by yourself in PySimpleGUI.

    Following code show the way

    import PySimpleGUI as sg
    
    def popup(message):
        global win
        if win:
            win.close()
        layout = [[sg.Text(message, background_color=bg, pad=(0, 0))]]
        win = sg.Window('title', layout, no_titlebar=True, keep_on_top=True,
            location=(1000, 200), auto_close=True, auto_close_duration=3,
            transparent_color=bg, margins=(0, 0))
        event, values = win.read(timeout=0)
        return win
    
    bg = '#add123'
    sg.set_options(font=("Courier New", 24))
    layout = [[sg.Button('POPUP')]]
    window = sg.Window('title', layout)
    win = None
    while True:
    
        event, value = window.read()
        if event == sg.WIN_CLOSED:
            break
        elif event == 'POPUP':
            win = popup('Here is the message.')
            window.force_focus()
    
    if win:
        win.close()
    window.close()