4

I've found some answers regarding displaying text on screen with Python. There's a lot about pop up messages and notifications.

However, I'm trying to create an unobtrusive little box (say, on the bottom of the screen maybe?). Something that'll be like a transparent overlay where messages will pop up in different colors while you're working. Like a notification box that is independent.

I don't have background in pygtk or tkinter or anything to do with GUI really (I'm a web developer). I don't know how to do this and all my Google searches give me examples of popping alerts on screen or communicating with the system's notifications which isn't relevant (cause I have little control over the appearence of that).

How do I do this?

yuvi
  • 18,155
  • 8
  • 56
  • 93
  • Probably is. If you're familiar with pywin32 and or pygtk/pyqt that can do these type of things. Your question is regarding a opinion, if it's hard or not. So I'm voting to close this. – Torxed Nov 05 '17 at 13:14
  • @Torxed there's no opinion here. I'm asking how to do it. I'm not familiar with pywin32 or pygtk\pyqt. I'm developing a tool and I don't know how to develop this one small part of it – yuvi Nov 05 '17 at 13:15
  • @Torxed I've edited the question to reflect what I'm asking – yuvi Nov 05 '17 at 13:17
  • Hate to be the picky one, but now there's not even a question in your *question* :) You found some answers already, and you're thinking of making a script. All good, but what have you tried? what's your issue? what do you need our help with? :P – Torxed Nov 05 '17 at 13:18
  • @Torxed but those answers solve a *different* problem. They showcase displaying text on screen, but it does so in a way that takes the entire screen, I need it to be unintrusive to the rest of the desktop. Think about it like this - I'm working on something, then someone sends a message, and my computer shows it at the bottom *without disrupting* my work – yuvi Nov 05 '17 at 13:22
  • @Torxed And yeah I haven't tried anything other than google. I always find it problematic to try things in an area I have no expertise in. I'm an experienced web developer but I'm shit when it comes to interacting with a desktop and anything to do with GUI in python – yuvi Nov 05 '17 at 13:24
  • @Torxed think about a notifications tool with more control (not something that'll communicate with the system's notifications but rather create its own) – yuvi Nov 05 '17 at 13:32
  • 2
    @Torxed edited the title and question again. Is that clearer? – yuvi Nov 05 '17 at 13:53
  • you are on windows or linux? – DRPK Nov 05 '17 at 14:19
  • @DRPK He's on Windows, according to the tag on the question :) – Torxed Nov 05 '17 at 15:15
  • 1
    @yuvi Here's a good starting point: https://stackoverflow.com/questions/21840133/how-to-display-text-on-the-screen-without-a-window-using-python – Torxed Nov 05 '17 at 15:17

1 Answers1

2

In your Case QT Or PYQT is the best!

why?!

Since you are on windows and you are a web developer, I highly recommend that you install ANACONDA. This way the environment variables are set automatically and you don't need to worry about anything else. There are many useful packages (e.g. pyqt, numpy, sympy, scipy) which are bundled with anaconda. with pyqt or QT you can set your stylesheets as css!!! or write html codes inside your style.

see : https://docs.anaconda.com/anaconda/packages/old-pkg-lists/4.3.0/py36

Try This ( a Simple transparent popup, based on css and pyqt ):

import sys
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtGui import *
from PyQt5 import QtCore
from PyQt5.QtWidgets import *
from PyQt5.QtCore import pyqtSignal
from PyQt5.QtCore import *


class MyNotification(QMainWindow):

    def __init__(self):

        QMainWindow.__init__(self)

        # < Styles >
        self.background_style_css = "background-color: rgba(22, 160, 133, 100); border-radius: 4px;"
        self.close_button_style_css = """
                                        QPushButton{
                                                    background-color: none;
                                                    color: white; border-radius: 6px;
                                                    font-size: 18px;
                                                    }
                                    """
        # </ Styles >

        # < Global Settings >
        self.setFixedSize(510, 210)
        self.move(400, 30)
        # </ Global Settings >

        # < Main Style >
        self.main_back = QLabel(self)
        self.main_back.resize(500, 200)
        self.main_back.setStyleSheet(self.background_style_css)
        # </ Main Style >

        # < Text Label >
        self.text_label = QLabel(self)
        self.text_label.move(10, 5)
        self.text_label.resize(300, 100)
        self.text_label.setText("Hi YUVI, How are You ? :)")
        # < Text Label >

        # < Header Style >
        self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
        self.setAttribute(QtCore.Qt.WA_TranslucentBackground)

        # This Line Set Your Window Always on To
        self.setWindowFlags(Qt.SplashScreen | Qt.WindowStaysOnTopHint)
        # </ Header Style >

    def terminal_ask(self):

        while True:

            print("If you want to close this window, type stop: ")

            get_input = input()

            if get_input.lstrip().rstrip().lower() == "stop":
                self.close_window()

            else:
                print("Invalid Syntax, Try it again.")

            QApplication.processEvents()

    def close_window(self):

        self.close()
        sys.exit()


if __name__ == '__main__':

    My_Application = QApplication(sys.argv)
    MainWindow = MyNotification()
    MainWindow.show()
    MainWindow.terminal_ask()
    sys.exit(My_Application.exec_())

NOTE: You Can see, i set some styles for each part of my code by setStyleSheet() function with css! read my internal comments, and change this code by yourself.

UPDATE :

Now You have static, always_on_top and terminal_asker window, if you type "stop", it will be closed.

Good Luck ...

DRPK
  • 2,023
  • 1
  • 14
  • 27
  • Really can't stand Anaconda tbh, I always feel like it takes over everything and if you decide to uninstall it it leaves such a mess behind. I'm gonna test this soon but I am curious if this window can appear as a static overlay on the screen? i.e. you can only close it through the terminal and it's like a sticky note that's always on top. – yuvi Nov 05 '17 at 19:14
  • 1
    @yuvi: Done! Check it again ( static, always on top, terminal asker ) – DRPK Nov 05 '17 at 20:38
  • This is perfect. Thank you. – yuvi Nov 05 '17 at 23:55
  • Added a bounty to reward you, because this is very spot on, but I have to wait a day before I can apply it. – yuvi Nov 08 '17 at 18:06
  • @DRPK: your edit broke your code - you are not using QPushButton anymore and you are not entering the event loop, because you are calling `terminal_ask` before, which is a loop – Skandix Nov 05 '18 at 10:08