Home > Mobile >  Python, tkinter how to make the window click-through Linux
Python, tkinter how to make the window click-through Linux

Time:04-29

I have seen the post about how to do it on Windows, but i need a Linux version. Is there any way? (Yes, i Googled before i came here) What i basically want to do is to open a maximized transparent click through window, to mainly use it as a "dark reader" here my tiny code :)

from tkinter import * 
win = Tk()
win.geometry("%dx%d 0 0" % (win.winfo_screenwidth(), win.winfo_screenheight()))
win.wait_visibility(win)
win.configure(bg="black")
win.wm_attributes("-alpha", 0.5)

win.mainloop()

CodePudding user response:

Simplified Explication

@Z3r0ut, Your probably using python 2.x because that is what most Linux distributions use. If you want to run the code, you can simple start with this argument python %FILENAME%.py.

!/usr/bin/python
-*- encoding: utf8 -*-
try:
   import Tkinter as tk
   from Tkinter import *
except ImportError:

win = Tk()
win.geometry("%dx%d 0 0" % (win.winfo_screenwidth(), win.winfo_screenheight()))
win.wait_visibility(win)
win.configure(bg="black")
win.wm_attributes("-alpha", 0.5)

win.mainloop()

Detailed Explication

These effects depend on your operating system, therefore you can't make Linux re-create these effects like windows 10/11. For example, shader.dll is used for shaders, dynamic.dll is used for screen smoothing, fix.dll is used for styling windows. Every one, can be found on regedit.

It can be made, but you need third-party API's or links for your file. If you're trying to make it, I would recommend you using c/c for it!

CodePudding user response:

I forgot to answer my question, after i got the solution. Thanks to Andrew Hernandez, i checked out PyQT5 and with that i could make what i needed. Here the code:

from PyQt5 import QtCore, QtWidgets, QtGui
import sys

DR = QtWidgets.QApplication(sys.argv)
win = QtWidgets.QWidget()

screen = DR.primaryScreen()
size = screen.size()
w = size.width()
h = size.height()

win.resize(w, h)
win.setWindowTitle("Dark Reader")
win.setAttribute(QtCore.Qt.WA_TransparentForMouseEvents, True)
win.setStyleSheet("background-color: black;")
win.setWindowOpacity(0.5)
win.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint | QtCore.Qt.FramelessWindowHint)
win.showMaximized()
sys.exit(DR.exec_())
  • Related