问题描述
我尝试使用 Python check if a process is running or not 中的答案来帮助我。但是,当我尝试在我的代码中实现 psutil 时,它并没有成功。
我使用 tkinter 创建了一个 GUI,我正在尝试使它在应用程序打开后立即移动到所选位置。我是否错误地使用了 psutil?
这是我的部分代码:
if clicked1.get() == "Google Chrome"
os.startfile(r"{google chrome file location}")
time.sleep(4) # time.sleep to allow the application time to open
app.connect(path=r"{google chrome file location}")
app1 = app.top_window()
app1.move_window(-20,-2150) # moves application to those x and y coordinates
time.sleep(.5) # gives the application time to move before maximizing
app1.maximize()
这是我尝试实现 psutil 时的代码:
if clicked1.get() == "Google Chrome"
os.startfile(r"{google chrome file location}")
while True:
if "Google Chrome" in (p.name() for p in psutil.process_iter()
app.connect(path=r"{google chrome file location}")
app1 = app.top_window()
app1.move_window(-20,-2150) # moves application to those x and y coordinates
time.sleep(.5) # gives the application time to move before maximizing
app1.maximize()
break # breaks from the loop when the application is started and is moved
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)