我是 python 编程和技巧的新手,学习让我创建一个项目.这就是我想要做的.我想创建一个在系统托盘中运行的程序并启动一个在后台加载的程序.在后台加载,这样我可以减少 Kivy 的启动时间.在这里和谷歌上搜索后,我找不到答案.
I'm a newby with python programming and tought, to learn let me create a project. 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. After searching here and on google, i could not find the answer.
我有两个文件
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()
和
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()
当我左键单击系统托盘图标时,我收到错误消息:AttributeError: 'NoneType' object has no attribute 'show'".我做错了什么?
When i left click the system tray icon, i get the error: "AttributeError: 'NoneType' object has no attribute 'show'". What am I doing wrong?
Kivy 是专门为Android 平台制作的,但这并不意味着它不能用于桌面应用程序开发.但请记住,窗口管理器将 SLD2 提供程序保持为支持状态,因此此提供程序支持隐藏窗口但无法恢复它.
Kivy was made specially for Android Platform but it does not mean that it can't be used for desktop application development. 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.
对于隐藏窗口,您可以使用:Window.hide() after importing Window from kivy.core.window
For hiding window you can use : Window.hide() after importing Window from kivy.core.window
对于恢复,您可以使用:Window.restore() 或 Window.show()
And for restoring you can use: Window.restore() or Window.show()
这篇关于Kivy 窗口隐藏/显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!