0

I want to add a color dot indicator that shows a green dot on-screen when VPN connected and red when disconnected. I want to display only the dot on the screen, not the whole window containing a red dot inside it. I have tried using pygame, but it shows the whole window with a red dot inside it. Please help me to resolve this issue.

import pygame
import time

WHITE =     (255, 255, 255)
RED =       (255,   0,   0)
(width, height) = (40, 40)

background_color = WHITE

pygame.init()
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption("VPN-Status")
screen.fill(background_color)
pygame.display.update()

while True:
    pygame.draw.circle(screen, RED, (20, 20), 20)
    pygame.display.update()
    time.sleep(0.25)
    pygame.draw.circle(screen, WHITE, (20, 20), 20)
    pygame.display.update()
    time.sleep(0.25)
Delrius Euphoria
  • 14,910
  • 3
  • 15
  • 46
Gokul
  • 1
  • 3
  • Means you want the red dot in terminal/console? – Dr. Strange Codes Jun 03 '21 at 03:35
  • Not in the terminal. I want to display it somewhere on the screen like whenever VPN gets disconnected it should show me a red dot on the screen. Using pygame I am able to do it but the problem is that a red dot appears inside a window. I just want the red dot to appear not the whole new small window with red dot. – Gokul Jun 03 '21 at 04:35
  • Do it by using Tkinter or Pygame. – Dr. Strange Codes Jun 03 '21 at 04:37
  • You can remove the window border using `pygame.display.set_mode((width, height), pygame.NOFRAME)`. – acw1668 Jun 03 '21 at 04:48
  • Thanks, @acw1668 that helped me remove the border. Is there any way that I can remove the white background and display only the red dot? – Gokul Jun 03 '21 at 05:47
  • If your platform is Windows, you can try with this [answer](https://stackoverflow.com/a/51845075/5317403). It is easier to do what you want using tkinter. – acw1668 Jun 03 '21 at 06:03
  • What you are looking for is "shaped windows". I think this [link](https://stackoverflow.com/questions/4873063/what-is-the-simplest-way-to-create-a-shaped-window-in-wxpython) maybe? – PoDuck Jun 03 '21 at 23:14

2 Answers2

0

If you want to show red and green dots in the terminal, try the below code. You will have to install a module. Use pip install colorama and pip install termcolor command to install it.

from colorama import init
from termcolor import colored
 
init()
 
print(colored('•', 'green'))
print(colored('•', 'red'))

The dots will be a little small.

0

Your pygame example is mostly correct, except you want to remove the white background. You have the background color set as white:

WHITE = (255, 255, 255)

background_color = WHITE

The problem is there is no alpha channel, which controls the transparency.

Try using this, with a transparency of 0 (transparent).


CLEAR = pygame.Color('#00000000')

background_color = CLEAR
Dharman
  • 30,962
  • 25
  • 85
  • 135