简体   繁体   English

Kivy 窗口隐藏/显示

[英]Kivy window hide/show

I'm a newby with python programming and tought, to learn let me create a project.我是python编程和tought的新手,学习让我创建一个项目。 Here is what i'm trying to do.这就是我想要做的。 I want to create a program that runs in system tray and fire's a program that is loaded in the background.我想创建一个在系统托盘中运行的程序并触发一个在后台加载的程序。 Loaded in the background so I can reduce the start time of Kivy.在后台加载,所以我可以减少 Kivy 的启动时间。 After searching here and on google, i could not find the answer.在这里和谷歌上搜索后,我找不到答案。

I have two files我有两个文件

from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.uix.boxlayout import BoxLayout
from kivy.config import Config
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.core.window import Window
from kivy.config import Config
# 

import kivy
from kivy.app import App
from kivy.uix.button import Button
from kivy.core.window import Window

Config.set('graphics', 'window_state', 'hidden')

class MyApp(App):
    visible = False

    def build(self):
        Window.bordeless = 'True'
        return Button(text='Hello World')

    def on_start(self):
        if self.visible:
            self.root_window.hide()
        self.visible = not self.visible
        # self.root.focus = True

    def do_show(self):
        rootWindow = self.root_window
        rootWindow.show()
        print(self.root_window.focus)

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

and

import wx
import someKivyThigy
from kivy.app import App
from someKivyThigy import MyApp
from buttonThing import MyDebugApp
from kivy.core.window import Window

TRAY_TOOLTIP = 'System Tray Demo'
TRAY_ICON = 'icon.png'

testVar = MyApp

def create_menu_item(menu, label, func):
    item = wx.MenuItem(menu, -1, label)
    menu.Bind(wx.EVT_MENU, func, id=item.GetId())
    menu.AppendItem(item)
    return item


class TaskBarIcon(wx.TaskBarIcon):
    def __init__(self):
        super(TaskBarIcon, self).__init__()
        self.set_icon(TRAY_ICON)
        self.Bind(wx.EVT_TASKBAR_LEFT_DOWN, self.on_left_down)

    def CreatePopupMenu(self):
        menu = wx.Menu()
        create_menu_item(menu, 'Say Hello', self.on_hello)
        menu.AppendSeparator()
        create_menu_item(menu, 'Exit', self.on_exit)
        return menu

    def set_icon(self, path):
        icon = wx.IconFromBitmap(wx.Bitmap(path))
        self.SetIcon(icon, TRAY_TOOLTIP)

    def on_left_down(self, event):
        print 'Tray icon was left-clicked.'
        MyApp().do_show()


    def on_hello(self, event):
        print 'Hello, world!'

    def on_exit(self, event):
        wx.CallAfter(self.Destroy)


def main():
    app = wx.PySimpleApp()
    TaskBarIcon()
    testVar = MyApp().run()
    app.MainLoop()

if __name__ == '__main__':
    main()

When i left click the system tray icon, i get the error: "AttributeError: 'NoneType' object has no attribute 'show'".当我左键单击系统托盘图标时,出现错误:“AttributeError: 'NoneType' 对象没有属性 'show'”。 What am I doing wrong?我究竟做错了什么?

Kivy was made specially for Android Platform but it does not mean that it can't be used for desktop application development. Kivy 是专为 Android 平台开发的,但这并不意味着它不能用于桌面应用程序开发。 But keep in mind that Window manager works with keeping SLD2 provider as backened so, this provider supports hide the window but cannot restore it.但是请记住,窗口管理器可以将 SLD2 提供程序保持为后备状态,因此该提供程序支持隐藏窗口但无法恢复它。

For hiding window you can use : Window.hide() after importing Window from kivy.core.window对于隐藏窗口,您可以在从 kivy.core.window 导入 Window 后使用: Window.hide()

And for restoring you can use: Window.restore() or Window.show()对于恢复,您可以使用: Window.restore() 或 Window.show()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM