怎样做才能让网站帮忙送东西,枣强做百度网站,wordpress 默认页面,第一次做网站做什么比较好Python程序互斥体 有时候我们需要程序只运行一个实例#xff0c;在windows平台下我们可以很简单的用mutex实现这个目的。 在开始时#xff0c;程序创建了一个命名的mutex#xff0c;这个mutex可以被其他进程检测到。 这样如果程序已经启动#xff0c;再次运行时的进程就…Python程序互斥体 有时候我们需要程序只运行一个实例在windows平台下我们可以很简单的用mutex实现这个目的。 在开始时程序创建了一个命名的mutex这个mutex可以被其他进程检测到。 这样如果程序已经启动再次运行时的进程就可以检测到程序已运行从而不会继续运行。 from tkinter import *
import win32event, pywintypes, win32api
from winerror import ERROR_ALREADY_EXISTS
class MyFrm(Frame):def __init__(self, master):self.rootmasterself.screen_width self.root.winfo_screenwidth()#获得屏幕宽度self.screen_height self.root.winfo_screenheight() #获得屏幕高度#self.root.resizable(False, False)#让高宽都固定self.root.update_idletasks()#刷新GUIself.root.withdraw() #暂时不显示窗口来移动位置self.root.geometry(%dx%d%d%d % (self.root.winfo_width(), self.root.winfo_height() ,(self.screen_width - self.root.winfo_width()) / 2,(self.screen_height - self.root.winfo_height()) / 2)) # center window on desktopself.root.deiconify()Label(self.root,text程序运行中...).pack(fillBOTH,expandYES)if __name____main__:mutexname DEMO#互斥体命名mutex win32event.CreateMutex(None, FALSE, mutexname)if (win32api.GetLastError() ERROR_ALREADY_EXISTS):print(程序已启动)exit(0)rootTk()MyFrm(root)root.mainloop() 转载于:https://www.cnblogs.com/d0main/p/7613302.html