python - 将光标的焦点设置回 Python
问题描述
我有一个使用 TKinter 打开 csv 的小程序。一切正常。
当用户选择一个文件时,我希望光标和活动窗口返回到 Python shell。
我正在使用这个:
os.system('''/usr/bin/osascript -e 'tell app "Finder" to set frontmost of process "Python" to true' ''')
当处于空闲状态时,这在程序运行时有效,但是当我双击 .py 文件并在 Python Shell 中运行它时,它说找不到路径。
有人知道我需要的路径吗?
谢谢,
解决方案
进一步研究,这是我的解决方案。
import win32gui as wg
from win32gui import GetWindowText, GetForegroundWindow
#This gets the details of the current window, the one running the program
aw = (GetForegroundWindow())
#Do some stuff..
#This tells the program to set the focus on the captured window
wg.SetForegroundWindow(aw)
我希望这可以帮助其他寻找与我相同的人。:-)
推荐阅读
- statistics - 比例测试:Z-test vs bootstrap/permutation - 不同的结果
- google-bigquery - 在 Terraform 中创建 BigQuery 视图
- c - 简单的单链表问题 - 节点值不显示
- reactjs - 如何使用 Enzyme 在 React Router/Redux 应用程序中对 React 组件方法的输出进行单元测试
- r - 如何为R中数据框中的某些条目创建空白?
- javascript - react native run ios build 成功但没有显示
- javascript - React 表格行上的 OnClick 事件
- php - 邮件不发送 我想发送邮件而不使用用户名和密码身份验证
- user-interface - Flutter 卡片列对齐和文本居中
- sql - 当其他人优先时,试图为事件争取时间