How to make the window transparent background in Kivy

Asked

Viewed 167 times

1

Hello, I am trying to make a program that creates a window without borders and with transparent background.

The first part I got:

Window.borderless = True

But I haven’t been able to make the background transparent yet. Does anyone know how to do that?

1 answer

1


Vitor uses this example function:

from kivy.config import Config

Config.set('graphics', 'position', 'custom')

Config.set('graphics', 'fullscreen', 'fake')

Config.set('graphics', 'top', '0')

Config.set('graphics', 'left', '0')

Config.set('graphics', 'resizable',  True)

from kivy.app import App

from kivy.uix.label import Label

from kivy.core.window import Window

Window.size = (1000, 500)

from kivy.uix.widget import Widget

from kivy.uix.boxlayout import BoxLayout

from kivy.uix.textinput import TextInput

from kivy.uix.button import Button

from kivy.uix.floatlayout import FloatLayout

from kivy.graphics import Color, Ellipse, Line,Rectangle

from kivy.uix.screenmanager import ScreenManager, Screen

from kivy.uix.relativelayout import RelativeLayout

from kivy.uix.image import Image

import win32gui

import win32con

import win32api,pywintypes

import win32gui

import win32con

import win32api,pywintypes

class Program(App):

    def on_start(self):

        hwnd = win32gui.FindWindow(None, "pencere")

        win32gui.SetWindowLong(hwnd, win32con.GWL_EXSTYLE,win32gui.GetWindowLong(hwnd,win32con.GWL_EXSTYLE) | win32con.WS_EX_LAYERED | win32con.WS_CHILD | win32con.WS_EX_TRANSPARENT |win32con.WS_EX_TOPMOST)

        win32gui.SetLayeredWindowAttributes(hwnd, win32api.RGB(255, 0, 128),40, win32con.LWA_ALPHA)

    def build(self):

        sm = ScreenManager()

        duzen = FloatLayout()

        screen = Screen(name='deneme ekran 1')

        self.title = "pencere"

        yazi = Label(text = self.title,pos=(10,10),size=(100,35),size_hint=(None,None),halign="center",bold=True,color=(1,1,1,1))

        buton = Button(text="",size_hint=(None,None),size=(26,26))

        buton.pos = (0,0)

        buton.background_normal = "minimize.png"

        buton.background_down = "minimize.png"

        with Window.canvas:

            Color(0,1,0,1)

            Rectangle(pos=(10, 10), size=(100, 40))

            duzen.add_widget(yazi)

        return duzen

Program().run()

I used it when I started, I took it out of Ddit.

Follows reference: Link

  • I’ll see if I can do anything with it... Anyway, thanks for your help!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.