Transparent background in a Tkinter window
There is no cross-platform way to make just the background transparent in tkinter.
Display an image with transparency and no background or window in Python
Thanks to the suggestion from Kartikeya, I was able to solve my own question.
Using PyQt5, this code will display an image with transparency and no border or background at all
import sys
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import QMainWindow, QApplication, QLabel
app = QApplication(sys.argv)
window = QMainWindow()
window.setAttribute(Qt.WA_TranslucentBackground, True)
window.setAttribute(Qt.WA_NoSystemBackground, True)
window.setWindowFlags(Qt.FramelessWindowHint)
label = QLabel(window)
pixmap = QPixmap('image.png')
label.setPixmap(pixmap)
label.setGeometry(0, 0, pixmap.width(), pixmap.height())
window.label = label
window.resize(pixmap.width(),pixmap.height())
window.show()
sys.exit(app.exec_())
Once I was looking for PyQt5, I found this question and only needed to modify the code slightly. Here is what it looks like now.
How to display TEXT ONLY (transparent background, with no menu bar or buttons) on screen using Python?
Transparent background of Text
in popup
is not supported.
New popup function required and defined by yourself in PySimpleGUI.
- Set option
background_color
of yourText
element to one specified color for transparency, like '#add123'. - Set option
transparent_color
inWindow
to the specified color for transparency. - Set option
no_titlebar
inWindow
to hide the titlebar.
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()
Related Topics
Pip Installing in Global Site-Packages Instead of Virtualenv
Check If a String in a Pandas Dataframe Column Is in a List of Strings
Escape String Python for MySQL
How to Pass an Operator to a Python Function
How Does Numpy's Transpose() Method Permute the Axes of an Array
How to Create Key or Append an Element to Key
Difference Between Methods and Functions, in Python Compared to C++
Fast Replacement of Values in a Numpy Array
How to Print One Character at a Time on One Line
Python: Source Code String Cannot Contain Null Bytes
How to Add Multiple Values to a Dictionary Key
Python: Count Repeated Elements in the List
How to Retrieve Items from a Dictionary in the Order That They'Re Inserted
Python Pandas Max Value in a Group as a New Column
How to Call a Shell Script from Python Code
When Would the -E, --Editable Option Be Useful with Pip Install