[英]Is there a way I can somehow pull all tabs I have open on my screen using python? On windows
I am making a small project of mine and I got stuck here, so basically I need a way to get my program a list of all the tabs I have open.我正在制作我的一个小项目,但我被困在这里,所以基本上我需要一种方法来让我的程序列出我打开的所有选项卡。 So I need a way to tell my program all the tabs I have open (exmpl. firefox, chrome, spotify...) and then it needs to find all tabs starting with a specific word.所以我需要一种方法来告诉我的程序我打开的所有选项卡(例如 firefox、chrome、spotify...),然后它需要找到以特定单词开头的所有选项卡。
import win32gui
def winEnumHandler( hwnd, ctx ):
if win32gui.IsWindowVisible( hwnd ):
print (hex(hwnd), win32gui.GetWindowText( hwnd ))
win32gui.EnumWindows( winEnumHandler, None )
I tried this yes it works but I need it to find all the windows starting with the same word but then have other words.我试过了,是的,它可以工作,但我需要它来找到所有以相同单词开头但有其他单词的 windows。 So for example EVE is a game when you join in on a account that windows is called EVE - (then the name of the account) but when you have multiple accounts they r not always gonna be the same name so I need it to find all the tabs starting with EVE.因此,例如,EVE 是一个游戏,当您加入 windows 称为 EVE 的帐户时 - (然后是帐户的名称)但是当您有多个帐户时,它们 r 并不总是同名,所以我需要它来查找所有以 EVE 开头的选项卡。
This is the output of this code.这是这个代码的output。
0x100ec
0x1014e
0x2033a Python - Get Started - Untitled (Workspace) - Visual Studio Code
0x40370 C:\Users\Leon\Desktop\Evetest2screenshot.py - Notepad++
0x102b0 Is there a way I can somehow pull all tabs I have open on my screen using python? On windows - Stack Overflow
- Google Chrome
0x1041a Signal
0x22082a New Tab - Google Chrome
0x3038c Command Prompt
0x30426
0x1084c Setup
0x101e4
0x101d8
0x101c6
0x101a4
0x101a2
0x70060 Microsoft Text Input Application
0x203aa Spotify Premium
0x20178 Program Manager
You can use psutil for this.您可以为此使用psutil 。 I have made the following which gives you a dictionary with a path if you desire to check it and a set/list of program names.我做了以下内容,如果您想检查它和程序名称的集合/列表,它会为您提供带有路径的字典。
import psutil
main_programs = {}
program_list = set()
for proc in psutil.process_iter():
try:
if proc.cmdline() != []:
main_programs[proc.name()] = proc.cmdline()[0] # Get the name and path to a dictionary
program_list.add(proc.name()) # Get the name to a set
except psutil.AccessDenied:
print("No perms")
search = "p"
for item in program_list:
if item.startswith(search):
print(item)
Output: Output:
powershell.exe
pythonw.exe
pycharm64.exe
EDIT编辑
list_programs = []
def winEnumHandler( hwnd, ctx ):
win32gui = {}
if win32gui.IsWindowVisible( hwnd ):
list_programs.append(win32gui.GetWindowText( hwnd ))
print (hex(hwnd), win32gui.GetWindowText( hwnd ))
search = "P"
for item in list_programs:
if item.startswith(search):
print(item)
Output Output
Python - Get Started - Untitled (Workspace) - Visual Studio Code
Program Manager
Yes it works, but it also gives me a list of all the processes.是的,它有效,但它也给了我所有进程的列表。 But is there a way to implement the search function into this?但是有没有办法实现搜索 function 到这个?
import win32gui
def winEnumHandler( hwnd, ctx ):
if win32gui.IsWindowVisible( hwnd ):
print (hex(hwnd), win32gui.GetWindowText( hwnd ))
win32gui.EnumWindows( winEnumHandler, None )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.