How can I hide the main window titlebar and place a transparent background in kivy framework?

对着背影说爱祢 提交于 2019-11-30 19:33:01

问题


I have a small problem and I am working on a small app that uses the python kivy gui framework. All i want is to hide the titlebar of the main window and make the background color transparent. I searched the net intensively but I couldn't find a solution for this.

Does anyone know how to do this?

Thanks


回答1:


You can disable bar using kivy.config.Config. Set fullscreen as fake:

from kivy.config import Config
Config.set('graphics', 'fullscreen', 'fake')

from kivy.app import App
from kivy.uix.button import Button

class MyApp(App):
    def build(self):
        button = Button(text="Exit", size_hint=(None, None))
        button.bind(on_press=exit)
        return button

if __name__ == '__main__':
    MyApp().run()

You can find more configuration options here: http://kivy.org/docs/api-kivy.config.html#available-configuration-tokens For example, to also change position of window:

from kivy.config import Config
Config.set('graphics', 'fullscreen', 'fake')
Config.set('graphics', 'position', 'custom')
Config.set('graphics', 'top', '300')
Config.set('graphics', 'left', '300')

from kivy.app import App
from kivy.uix.button import Button

class MyApp(App):
    def build(self):
        button = Button(text="Exit", size_hint=(None, None))
        button.bind(on_press=exit)
        return button

if __name__ == '__main__':
    MyApp().run()

Unfortunately, I don't know whether it's possible to add transparency.




回答2:


There is a simpler way:

from kivy.app import App
from kivy.core.window import Window

class MyApp(App):
    def build(self):
        Window.borderless = True

# ...

http://kivy.org/docs/api-kivy.core.window.html#kivy.core.window.WindowBase.borderless



来源:https://stackoverflow.com/questions/20613738/how-can-i-hide-the-main-window-titlebar-and-place-a-transparent-background-in-ki

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!