[英]How to switch to an already running application using WinAppDriver (Python)
[英]Python:How to prohibit opening of an application if it is already running
我设计Python编写与wxPython的 GUI的 works.I不用想,如果它已经打开了,打开我的软件适用于Windows 7在Windows实用软件。 我希望这样的功能,如果用户打开该软件,将在Windows屏幕上显示一个消息框,显示“您的应用程序已在运行”。
Plz的帮助。 提前致谢...
现有的wxPython工具已经实现了所需的逻辑,称为wx.SingleInstanceChecker
。 这是代码的例子(从wxPython wiki中无耻地借用):
import wx
class SingleAppFrame(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, title=title, size=(300, 300))
self.Centre()
class SingleApp(wx.App):
def OnInit(self):
self.name = "SingleApp-%s" % wx.GetUserId()
self.instance = wx.SingleInstanceChecker(self.name)
if self.instance.IsAnotherRunning():
wx.MessageBox("Another instance is running", "ERROR")
return False
frame = SingleAppFrame(None, "SingleApp")
frame.Show()
return True
app = SingleApp(redirect=False)
app.MainLoop()
这个非常典型的例子(为了运气)可以很好地满足你的要求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.