程序笔记   发布时间:2022-07-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了【Python GUI 窗口句柄定位】——使用鼠标指针定位窗口句柄并获得对应的程序属性值,针对流氓软件绰绰有余大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

GUI窗口 使用鼠标指针进行定位程序࿰c;获得程序的窗口句柄、窗口类名、窗口标题、线程ID、进程ID、进程名称、进程路径、CPU用量、线程数、窗口定位及鼠标坐标c;并附加五项可操作控件࿰c;强制置顶、取消置顶、显示顶部、前置终止、打开文件所在位置c;可显示定位程序的图标。

点个赞留个关注吧!!

资料下载:提取码:n8pk 源代码及图片 资料下载 14kb

将红色框的指针拖到指定程序上࿰c;就会获得属性值

【Python GUI 窗口句柄定位】——使用鼠标指针定位窗口句柄并获得对应的程序属性值,针对流氓软件绰绰有余

【Python GUI 窗口句柄定位】——使用鼠标指针定位窗口句柄并获得对应的程序属性值,针对流氓软件绰绰有余

 此程序使用要注意的事项:

使用须知: 1、在软件内有一个大的圆形图标࿰c;用鼠标左键进行拖拽到指定文件上会显示文件的所有属性 但不能左键一直拖动超过10秒࿰c;必须要松开一下在进行拖拽࿰c;否则会自动闪退࿰c;可能是因为电脑的性能问题导致的

2、软件内有五个按键 强制置顶可以置顶所有窗口࿰c;但不要置顶桌面࿰c;否则会覆盖你屏幕上所有的软件界面࿰c;只有使用取消置顶才可以取消掉 显示顶部࿰c;仅仅只是将某软件的界面显示到最顶层࿰c;但不是一直置顶 强制终止会终止一切的子程序࿰c;利用的是 程序名称和PID进行终止的 终止某个程序要谨慎࿰c;因为会把子程序也终止掉

3、二维码二维码由博主设计出来࿰c;切勿乱改࿰c;如有转载或使用࿰c;请标注出处和博主身份  

开始我们的程序

导入程序所需要的模块࿰c;如果没有模块的使用 pip install 进行安装࿰c;如果是版本不够可以加上-U进行更新升级࿰c;如果都不行可以去 python 模块官网 下载࿰c;然后使用 pip install *.whl 进行安装࿰c;要看清对应的版本࿰c;否则会报错

pip install 模块名

pip install -U 模块名

import tkinter
from tkinter import *
from tkinter.ttk import *
import win32api
import win32gui
import win32con
import win32ui
import time
from win32 import win32process
import psutil
import subprocess
from PIL import Image
import os

基本的GUI界面࿰c;程序的图标可要可不要࿰c;也可以自己去制作

root = Tk()
root.title('贱工坊-窗口句柄')  # 程序的标题名称
root.geometry("480x320+512+288")  # 窗口的大小及页面的显示位置
root.resizable(false, falsE)  # 固定页面不可放大缩小
root.iconbitmap("picture.ico")  # 程序的图标

在程序里创建画布改变颜色࿰c;添加图片࿰c;这个图片是圆形图标

    canvas = tkinter.Canvas(root, bg="#ebebeb", height=400, width=700, borderwidth=-3)  # 创建画布
    canvas.pack(side='top')  # 放置画布(为上端)

    canvas_2 = tkinter.Canvas(root, bg="#ebebeb",cursor='target', height=50, width=50, borderwidth=-2)  # 创建画布
    canvas_2.place(x=402, y=70)  # 放置画布(为上端)
    image_file = tkinter.PhotoImage(file="./Key.png")  # 加载图片文件
    canvas_2.create_image(0, 0, anchor='nw', image=image_filE)  # 将图片置于画布上

【Python GUI 窗口句柄定位】——使用鼠标指针定位窗口句柄并获得对应的程序属性值,针对流氓软件绰绰有余

在程序里添加文本框࿰c;用来放置数据 

    # 配置窗口句柄
    var_hwnd = tkinter.StringVar()
    tkinter.Entry(root, width=20,borderwidth=1,bg='#ebebeb',textvariable=var_hwnd).place(x=70,y=10)

    # 配置标题名称
    var_title = tkinter.StringVar()
    tkinter.Entry(root, width=54, borderwidth=1,bg='#ebebeb', textvariable=var_titlE).place(x=70, y=40)

    # 配置窗口类名
    var_clsname = tkinter.StringVar()
    tkinter.Entry(root, width=20, borderwidth=1, bg='#ebebeb', textvariable=var_clsName).place(x=306, y=10)

    # 配置线程ID
    var_hread_id = tkinter.StringVar()
    tkinter.Entry(root, width=10, borderwidth=1, bg='#ebebeb', textvariable=var_hread_id).place(x=70, y=70)

    # 配置进程ID
    var_process_id = tkinter.StringVar()
    tkinter.Entry(root, width=10, borderwidth=1, bg='#ebebeb', textvariable=var_process_id).place(x=204, y=70)

    # 配置程序名称
    var_process = tkinter.StringVar()
    tkinter.Entry(root, width=29, borderwidth=1, bg='#ebebeb', textvariable=var_process).place(x=70, y=100)

    # 配置程序路径
    var_p_bin = tkinter.StringVar()
    tkinter.Entry(root, width=54, borderwidth=1, bg='#ebebeb', textvariable=var_p_bin).place(x=70, y=130)

    # 配置CPU利用率
    var_mem_percent = tkinter.StringVar()
    tkinter.Entry(root, width=20, borderwidth=1, bg='#ebebeb', textvariable=var_mem_percent).place(x=70, y=160)

    # 配置线程数
    var_num_threads = tkinter.StringVar()
    tkinter.Entry(root, width=20, borderwidth=1, bg='#ebebeb', textvariable=var_num_threads).place(x=306, y=160)

    # 配置窗口左上
    var_top = tkinter.StringVar()
    tkinter.Entry(root, width=6, borderwidth=1, bg='#ebebeb', textvariable=var_top).place(x=70, y=190)

    # 配置窗口左下
    var_left = tkinter.StringVar()
    tkinter.Entry(root, width=6, borderwidth=1, bg='#ebebeb', textvariable=var_left).place(x=70, y=220)

    # 配置窗口右上
    var_right = tkinter.StringVar()
    tkinter.Entry(root, width=6, borderwidth=1, bg='#ebebeb', textvariable=var_right).place(x=194, y=190)

    # 配置窗口右下
    var_bottom = tkinter.StringVar()
    tkinter.Entry(root, width=6, borderwidth=1, bg='#ebebeb', textvariable=var_bottom).place(x=194, y=220)

    # 配置坐标x,y
    var_point = tkinter.StringVar()
    tkinter.Entry(root, width=24, borderwidth=1, bg='#ebebeb', textvariable=var_point).place(x=70, y=250)

【Python GUI 窗口句柄定位】——使用鼠标指针定位窗口句柄并获得对应的程序属性值,针对流氓软件绰绰有余

 程序添加标签࿰c;用来标注

        tkinter.Label(canvas, bg="#ebebeb", text='窗口句柄').place(x=10, y=8)
        tkinter.Label(canvas, bg="#ebebeb", text='窗口标题').place(x=10, y=38)
        tkinter.Label(canvas, bg="#ebebeb", text='窗口类名').place(x=248, y=8)
        tkinter.Label(canvas, bg="#ebebeb", text='线程ID').place(x=10, y=68)
        tkinter.Label(canvas, bg="#ebebeb", text='进程ID').place(x=154, y=68)
        tkinter.Label(canvas, bg="#ebebeb", text='进程名称').place(x=10, y=98)
        tkinter.Label(canvas, bg="#ebebeb", text='进程路径').place(x=10, y=128)
        tkinter.Label(canvas, bg="#ebebeb", text='CPU用量').place(x=10, y=158)
        tkinter.Label(canvas, bg="#ebebeb", text='线程数').place(x=258, y=158)
        tkinter.Label(canvas, bg="#ebebeb", text='窗口左上').place(x=10, y=188)
        tkinter.Label(canvas, bg="#ebebeb", text='窗口左下').place(x=10, y=218)
        tkinter.Label(canvas, bg="#ebebeb", text='窗口右上').place(x=134, y=188)
        tkinter.Label(canvas, bg="#ebebeb", text='窗口右下').place(x=134, y=218)
        tkinter.Label(canvas, bg="#ebebeb", text='坐标x,y').place(x=10, y=248)

【Python GUI 窗口句柄定位】——使用鼠标指针定位窗口句柄并获得对应的程序属性值,针对流氓软件绰绰有余

程序内放置一个CSDN博主二维码࿰c;直达博主主页࿰c;图片的尺寸是 200x80 ࿰c;二维码由博主制作࿰c;内置为博主的主页链接

    # 放置二维码
    canvas_4 = tkinter.Canvas(root, bg="red", height=80, width=200, borderwidth=-2)
    canvas_4.place(x=250, y=190)
    image_file_4 = tkinter.PhotoImage(file="./share.png")  # 加载图片文件
    canvas_4.create_image(0, 0, anchor='nw', image=image_file_4)  # 将图片置于画布上

【Python GUI 窗口句柄定位】——使用鼠标指针定位窗口句柄并获得对应的程序属性值,针对流氓软件绰绰有余

 获取鼠标的坐标࿰c;通过坐标获取窗口句柄c;然后通过句柄获取窗口标题、窗口类名、线程ID、进程ID和窗口坐标࿰c;然后通过进程ID获取程序名称、程序路径、CUP用量和线程数࿰c;通过程序路径获取软件图标࿰c;这里关联着鼠标的bind <B1-Motion>左键持续移动࿰c;只要鼠标左键持续移动则会执行如下代码࿰c;动一下执行一次

            point = win32api.GetcursorPos()  # 鼠标位置
            hwnd = win32gui.WindowFromPoint(point)   # 窗口句柄
            title = win32gui.GetWindowText(hwnd)    # 窗口标题
            clsname = win32gui.GetClassName(hwnd)   # 窗口类名
            hread_id, process_id = win32process.GetWindowThreadProcessId(hwnd)  #线程ID  进程ID
            process = psutil.Process(process_id)     # 程序名称  通过进程ID获取
            p_bin = psutil.Process(process_id).exe()   # 程序路径  通过进程ID获取
            mem_percent = psutil.Process(process_id).memory_percent()   # CPU利用率  通过进程ID获取
            num_threads = psutil.Process(process_id).num_threads()     # 线程数  通过进程ID获取
            left, top, right, bottom = win32gui.GetWindowRect(hwnd)   #窗口坐标  通过窗口句柄获取 四个角的坐标
            picture()    # 更换软件图标
            ICON(p_bin)  # 获取软件图标
            var_hwnd.set(hwnd)
            var_title.set(titlE)
            var_clsname.set(clsName)
            var_hread_id.set(hread_id)
            var_process_id.set(process_id)
            var_process.set(process.name())
            var_p_bin.set(p_bin)
            var_mem_percent.set(mem_percent)
            var_num_threads.set(num_threads)
            var_left.set(left)
            var_top.set(top)
            var_right.set(right)
            var_bottom.set(bottom)
            var_point.set(point)

这个代码的用处是用来获取软件的图标࿰c;通过路径获取࿰c;并持续保存替换 icon.png 图片

# 获取软件图标
    def ICON(exePath2):
        try:
            exePath = exePath2.replace("\", "/")  # 替换
            large, small = win32gui.ExtractIconEx(f'{exePath}', 0)
            useIcon = large[0]
            destroyIcon = small[0]
            win32gui.DestroyIcon(destroyIcon)
            hdc = win32ui.CreateDCFromHandle(win32gui.GetDC(0))
            hbmp = win32ui.CreateBitmap()
            hbmp.CreateCompatibleBitmap(hdc, ico_x, ico_X)
            hdc = hdc.CreateCompatibleDC()
            hdc.SELEctObject(hbmp)
            hdc.DrawIcon((0, 0), useIcon)
            bmpstr = hbmp.GetBitmapBits(true)
            img = Image.frombuffer(
                'RGBA',
                (32, 32),
                bmpstr, 'Raw', 'BGRA', 0, 1
            )
            img.save('icon.png')
        except:
            pass

将保存好扽图片进行加载进来࿰c;pictures.png 是软件的默认图标࿰c;而 icon.png 则是保存下来的图标进行替换࿰c;所以指针指向哪里就会替换为哪一个软件的图标࿰c;原理就是这样࿰c;只是有一部分的软件图标获取不了或使用不了࿰c;会造成软件内图标变白

    image_file_3 = tkinter.PhotoImage(file="pictures.png")  # 软件第一次打开时要呈现的图片
    Button_2 = Button(canvas_3,image=image_file_3).place(x=0, y=0)
    # 更换软件图标
    def picture():
        try:
            image_file_3.config(file='icon.png')   # 替换
        except:
            pass

这是能获取到图标的

【Python GUI 窗口句柄定位】——使用鼠标指针定位窗口句柄并获得对应的程序属性值,针对流氓软件绰绰有余

 这是获取不到图标或使用不了图标的࿰c;只有绝少部分获取不到或使用不了࿰c;不影响软件的使用。

【Python GUI 窗口句柄定位】——使用鼠标指针定位窗口句柄并获得对应的程序属性值,针对流氓软件绰绰有余

 下面的是按钮所对应的函数控件࿰c;用来置顶、取消置顶、显示顶部、终止程序和打开文件所在位置࿰c;这里要注意的是我采用的taskkill 电脑自带的终止指令࿰c;可以不会支持Win7以下的电脑命令࿰c;还有就是我这个终止命令会把程序的子程序也终止掉࿰c;所以尽量不要去尝试终止文件夹和桌面之类的࿰c;如果终止掉了屏幕会全白࿰c;可以使用【ctrl+alt+delete】进入任务管理器࿰c;新建任务࿰c;explorer 回车即可恢复࿰c;但是有可能你的资料都会被强行关闭。

    # 置顶 通过句柄
    def set_top():
        try:
            win32gui.SetWindowPos(var_hwnd.get(), win32con.HWND_TOPMOST, 0, 0, 0, 0,win32con.SWP_NOMOVE | win32con.SWP_NOACTIVATE | win32con.SWP_NOowneRZORDER | win32con.SWP_SHOWWINDOW | win32con.SWP_NOSIZE)
        except:
            pass
    # 取消置顶 通过句柄
    def set_down():
        try:
            win32gui.SetWindowPos(var_hwnd.get(), win32con.HWND_NOTOPMOST, 0, 0, 0, 0,win32con.SWP_SHOWWINDOW | win32con.SWP_NOSIZE | win32con.SWP_NOMOVE)
        except:
            pass
    # 显示在顶部 通过句柄
    def set_yop_p():
        try:
            win32gui.SetForegroundWindow(var_hwnd.get())
        except:
            pass

    # 终止程序
    def kill():
        try:
            subprocess.Popen("taskkill /F /T /PID " + var_process_id.get(), sHell=TruE)
            subprocess.Popen("taskkill /F /T /IM " + process.get(), sHell=TruE)
        except:
            pass

    # 打开文件夹
    def bin():
        pbin = var_p_bin.get().replace("\", "/")  # 替换
        pbin = os.path.split(pbin)[0].replace("\", "/")
        os.startfile(str(pbin))

按钮控件

    Button(root, text='强制置顶',   command=set_top).place(x=10, y=280)
    Button(root, text='取消置顶', command=set_down).place(x=100, y=280)
    Button(root, text='显示顶部', command=set_yop_p).place(x=190, y=280)
    Button(root, text='强制终止', command=kill).place(x=280, y=280)
    Button(root, text='打开文件所在位置', command=bin).place(x=370, y=280)

【Python GUI 窗口句柄定位】——使用鼠标指针定位窗口句柄并获得对应的程序属性值,针对流氓软件绰绰有余

 这个是最关键的࿰c;只有这个控件才能起到指针移动是执行命令࿰c;canvas_2 指的是在 canvas_2的画布下可以使用࿰c;<B1-Motion> 指的是鼠标左键并移动 待触发控件࿰c;showMenu 指的是要执行的命令函数࿰c;

# 鼠标移动控件
    canvas_2.bind("<B1-Motion>", showMenu)

废话不多说࿰c;上代码。

运行不成功的可以要注意࿰c;是不是没有图片࿰c;最上方有资料链接࿰c;里面包括图片和源文件࿰c;可以免费下载c;代码都不用复制了

完整代码:

import tkinter
from tkinter import *
from tkinter.ttk import *
import win32api
import win32gui
import win32con
import win32ui
import time
from win32 import win32process
import psutil
import subprocess
from PIL import Image
import os

def main():
    root = Tk()
    root.title('贱工坊-窗口句柄')  # 程序的标题名称
    root.geometry("480x320+512+288")  # 窗口的大小及页面的显示位置
    root.resizable(false, falsE)  # 固定页面不可放大缩小
    root.iconbitmap("picture.ico")  # 程序的图标

    canvas = tkinter.Canvas(root, bg="#ebebeb", height=400, width=700, borderwidth=-3)  # 创建画布
    canvas.pack(side='top')  # 放置画布(为上端)

    canvas_2 = tkinter.Canvas(root, bg="#ebebeb",cursor='target', height=50, width=50, borderwidth=-2)  # 创建画布
    canvas_2.place(x=402, y=70)  # 放置画布(为上端)
    image_file = tkinter.PhotoImage(file="./Key.png")  # 加载图片文件
    canvas_2.create_image(0, 0, anchor='nw', image=image_filE)  # 将图片置于画布上

    canvas_3 = tkinter.Canvas(root, bg="red",  height=40, width=40, borderwidth=-2)  # 创建画布
    canvas_3.place(x=332, y=74)  # 放置画布(为上端)


    # 配置窗口句柄
    var_hwnd = tkinter.StringVar()
    tkinter.Entry(root, width=20,borderwidth=1,bg='#ebebeb',textvariable=var_hwnd).place(x=70,y=10)

    # 配置标题名称
    var_title = tkinter.StringVar()
    tkinter.Entry(root, width=54, borderwidth=1,bg='#ebebeb', textvariable=var_titlE).place(x=70, y=40)

    # 配置窗口类名
    var_clsname = tkinter.StringVar()
    tkinter.Entry(root, width=20, borderwidth=1, bg='#ebebeb', textvariable=var_clsName).place(x=306, y=10)

    # 配置线程ID
    var_hread_id = tkinter.StringVar()
    tkinter.Entry(root, width=10, borderwidth=1, bg='#ebebeb', textvariable=var_hread_id).place(x=70, y=70)

    # 配置进程ID
    var_process_id = tkinter.StringVar()
    tkinter.Entry(root, width=10, borderwidth=1, bg='#ebebeb', textvariable=var_process_id).place(x=204, y=70)

    # 配置程序名称
    var_process = tkinter.StringVar()
    tkinter.Entry(root, width=29, borderwidth=1, bg='#ebebeb', textvariable=var_process).place(x=70, y=100)

    # 配置程序路径
    var_p_bin = tkinter.StringVar()
    tkinter.Entry(root, width=54, borderwidth=1, bg='#ebebeb', textvariable=var_p_bin).place(x=70, y=130)

    # 配置CPU利用率
    var_mem_percent = tkinter.StringVar()
    tkinter.Entry(root, width=20, borderwidth=1, bg='#ebebeb', textvariable=var_mem_percent).place(x=70, y=160)

    # 配置线程数
    var_num_threads = tkinter.StringVar()
    tkinter.Entry(root, width=20, borderwidth=1, bg='#ebebeb', textvariable=var_num_threads).place(x=306, y=160)

    # 配置窗口左上
    var_top = tkinter.StringVar()
    tkinter.Entry(root, width=6, borderwidth=1, bg='#ebebeb', textvariable=var_top).place(x=70, y=190)

    # 配置窗口左下
    var_left = tkinter.StringVar()
    tkinter.Entry(root, width=6, borderwidth=1, bg='#ebebeb', textvariable=var_left).place(x=70, y=220)

    # 配置窗口右上
    var_right = tkinter.StringVar()
    tkinter.Entry(root, width=6, borderwidth=1, bg='#ebebeb', textvariable=var_right).place(x=194, y=190)

    # 配置窗口右下
    var_bottom = tkinter.StringVar()
    tkinter.Entry(root, width=6, borderwidth=1, bg='#ebebeb', textvariable=var_bottom).place(x=194, y=220)

    # 配置坐标x,y
    var_point = tkinter.StringVar()
    tkinter.Entry(root, width=24, borderwidth=1, bg='#ebebeb', textvariable=var_point).place(x=70, y=250)

    image_file_3 = tkinter.PhotoImage(file="pictures.png")  # 软件第一次打开时要呈现的图片
    Button_2 = Button(canvas_3, image=image_file_3).place(x=0, y=0)
    # 更换软件图标
    def picture():
        try:
            image_file_3.config(file='icon.png')   # 替换
        except:
            pass
    # 图标尺寸
    ico_x = 32
    # 获取软件图标
    def ICON(exePath2):
        try:
            exePath = exePath2.replace("\", "/")  # 替换
            large, small = win32gui.ExtractIconEx(f'{exePath}', 0)
            useIcon = large[0]
            destroyIcon = small[0]
            win32gui.DestroyIcon(destroyIcon)
            hdc = win32ui.CreateDCFromHandle(win32gui.GetDC(0))
            hbmp = win32ui.CreateBitmap()
            hbmp.CreateCompatibleBitmap(hdc, ico_x, ico_X)
            hdc = hdc.CreateCompatibleDC()
            hdc.SELEctObject(hbmp)
            hdc.DrawIcon((0, 0), useIcon)
            bmpstr = hbmp.GetBitmapBits(true)
            img = Image.frombuffer(
                'RGBA',
                (32, 32),
                bmpstr, 'Raw', 'BGRA', 0, 1
            )
            img.save('icon.png')
        except:
            pass


    # 通过鼠标移动获取函数
    def showMenu(event):
        try:
            point = win32api.GetcursorPos()  # 鼠标位置
            hwnd = win32gui.WindowFromPoint(point)   # 窗口句柄
            title = win32gui.GetWindowText(hwnd)    # 窗口标题
            clsname = win32gui.GetClassName(hwnd)   # 窗口类名
            hread_id, process_id = win32process.GetWindowThreadProcessId(hwnd)  #线程ID  进程ID
            process = psutil.Process(process_id)     # 程序名称  通过进程ID获取
            p_bin = psutil.Process(process_id).exe()   # 程序路径  通过进程ID获取
            mem_percent = psutil.Process(process_id).memory_percent()   # CPU利用率  通过进程ID获取
            num_threads = psutil.Process(process_id).num_threads()     # 线程数  通过进程ID获取
            left, top, right, bottom = win32gui.GetWindowRect(hwnd)   #窗口坐标  通过窗口句柄获取 四个角的坐标
            picture()    # 更换软件图标
            ICON(p_bin)  # 获取软件图标
            var_hwnd.set(hwnd)
            var_title.set(titlE)
            var_clsname.set(clsName)
            var_hread_id.set(hread_id)
            var_process_id.set(process_id)
            var_process.set(process.name())
            var_p_bin.set(p_bin)
            var_mem_percent.set(mem_percent)
            var_num_threads.set(num_threads)
            var_left.set(left)
            var_top.set(top)
            var_right.set(right)
            var_bottom.set(bottom)
            var_point.set(point)
        except:
            pass

    # 置顶 通过句柄
    def set_top():
        try:
            win32gui.SetWindowPos(var_hwnd.get(), win32con.HWND_TOPMOST, 0, 0, 0, 0,win32con.SWP_NOMOVE | win32con.SWP_NOACTIVATE | win32con.SWP_NOowneRZORDER | win32con.SWP_SHOWWINDOW | win32con.SWP_NOSIZE)
        except:
            pass
    # 取消置顶 通过句柄
    def set_down():
        try:
            win32gui.SetWindowPos(var_hwnd.get(), win32con.HWND_NOTOPMOST, 0, 0, 0, 0,win32con.SWP_SHOWWINDOW | win32con.SWP_NOSIZE | win32con.SWP_NOMOVE)
        except:
            pass
    # 显示在顶部 通过句柄
    def set_yop_p():
        try:
            win32gui.SetForegroundWindow(var_hwnd.get())
        except:
            pass

    # 终止程序
    def kill():
        try:
            subprocess.Popen("taskkill /F /T /PID " + var_process_id.get(), sHell=TruE)
            subprocess.Popen("taskkill /F /T /IM " + process.get(), sHell=TruE)
        except:
            pass

    # 打开文件夹
    def bin():
        pbin = var_p_bin.get().replace("\", "/")  # 替换
        pbin = os.path.split(pbin)[0].replace("\", "/")
        os.startfile(str(pbin))

    def Label():
        # 标签
        tkinter.Label(canvas, bg="#ebebeb", text='窗口句柄').place(x=10, y=8)
        tkinter.Label(canvas, bg="#ebebeb", text='窗口标题').place(x=10, y=38)
        tkinter.Label(canvas, bg="#ebebeb", text='窗口类名').place(x=248, y=8)
        tkinter.Label(canvas, bg="#ebebeb", text='线程ID').place(x=10, y=68)
        tkinter.Label(canvas, bg="#ebebeb", text='进程ID').place(x=154, y=68)
        tkinter.Label(canvas, bg="#ebebeb", text='进程名称').place(x=10, y=98)
        tkinter.Label(canvas, bg="#ebebeb", text='进程路径').place(x=10, y=128)
        tkinter.Label(canvas, bg="#ebebeb", text='CPU用量').place(x=10, y=158)
        tkinter.Label(canvas, bg="#ebebeb", text='线程数').place(x=258, y=158)
        tkinter.Label(canvas, bg="#ebebeb", text='窗口左上').place(x=10, y=188)
        tkinter.Label(canvas, bg="#ebebeb", text='窗口左下').place(x=10, y=218)
        tkinter.Label(canvas, bg="#ebebeb", text='窗口右上').place(x=134, y=188)
        tkinter.Label(canvas, bg="#ebebeb", text='窗口右下').place(x=134, y=218)
        tkinter.Label(canvas, bg="#ebebeb", text='坐标x,y').place(x=10, y=248)

    # 鼠标移动控件
    canvas_2.bind("<B1-Motion>", showMenu)
    Button(root, text='强制置顶',   command=set_top).place(x=10, y=280)
    Button(root, text='取消置顶', command=set_down).place(x=100, y=280)
    Button(root, text='显示顶部', command=set_yop_p).place(x=190, y=280)
    Button(root, text='强制终止', command=kill).place(x=280, y=280)
    Button(root, text='打开文件所在位置', command=bin).place(x=370, y=280)

    # 放置二维码
    canvas_4 = tkinter.Canvas(root, bg="red", height=80, width=200, borderwidth=-2)
    canvas_4.place(x=250, y=190)
    image_file_4 = tkinter.PhotoImage(file="./share.png")  # 加载图片文件
    canvas_4.create_image(0, 0, anchor='nw', image=image_file_4)  # 将图片置于画布上

    Label()
    root.mainloop() #运行

if __name__ == '__main__':
    main()

【Python GUI 窗口句柄定位】——使用鼠标指针定位窗口句柄并获得对应的程序属性值,针对流氓软件绰绰有余

大佬总结

以上是大佬教程为你收集整理的【Python GUI 窗口句柄定位】——使用鼠标指针定位窗口句柄并获得对应的程序属性值,针对流氓软件绰绰有余全部内容,希望文章能够帮你解决【Python GUI 窗口句柄定位】——使用鼠标指针定位窗口句柄并获得对应的程序属性值,针对流氓软件绰绰有余所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。