Here's a data driven approach that lets you add apps to the map at the top of the code, and also makes it easy for you to add additional per-app quantities to each of the map entries:
apps = {
"app1": {
"startfile": r"C:Users
edDesktopapp1",
"title_re": ".*app1"
},
"app2": {
"startfile": r"C:Program Files (x86)app2",
"title_re": ".*app2"
}
}
def click():
if clicked1.get() in apps:
app = apps[clicked1.get()]
os.startfile(app["startfile"])
i = 0
while i < 20:
try:
app.connect(title_re=app["title_re"])
break
except pywinauto.findwindows.ElementNotFoundError:
time.sleep(1)
i += 1
app1 = app.top_window()
app1.move_window(x1, y1)
time.sleep(.5)
app1.maximize()
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…