主頁 > 後端開發 > 【Python GUI 視窗句柄定位】——使用滑鼠指標定位視窗句柄并獲得對應的程式屬性值,針對流氓軟體綽綽有余

【Python GUI 視窗句柄定位】——使用滑鼠指標定位視窗句柄并獲得對應的程式屬性值,針對流氓軟體綽綽有余

2022-01-17 19:59:23 後端開發

GUI視窗 使用滑鼠指標進行定位程式,獲得程式的視窗句柄、視窗類名、視窗標題、執行緒ID、行程ID、行程名稱、行程路徑、CPU用量、執行緒數、視窗定位及滑鼠坐標,并附加五項可操作控制元件,強制置頂、取消置頂、顯示頂部、前置終止、打開檔案所在位置,可顯示定位程式的圖示,

點個贊留個關注吧!!

資料下載:提取碼:n8pk 源代碼及圖片 資料下載 14kb

將紅色框的指標拖到指定程式上,就會獲得屬性值

此程式使用要注意的事項:

使用須知:
1、在軟體內有一個大的圓形圖示,用滑鼠左鍵進行拖拽到指定檔案上會顯示檔案的所有屬性
但不能左鍵一直拖動超過10秒,必須要松開一下在進行拖拽,否則會自動閃退,可能是因為電腦的性能問題導致的

2、軟體內有五個按鍵
強制置頂可以置頂所有視窗,但不要置頂桌面,否則會覆寫你螢屏上所有的軟體界面,只有使用取消置頂才可以取消掉
顯示頂部,僅僅只是將某軟體的界面顯示到最頂層,但不是一直置頂
強制終止會終止一切的子程式,利用的是 程式名稱和PID進行終止的 終止某個程式要謹慎,因為會把子程式也終止掉

3、二維碼
二維碼由博主設計出來,切勿亂改,如有轉載或使用,請標注出處和博主身份

開始我們的程式

匯入程式所需要的模塊,如果沒有模塊的使用 pip install 進行安裝,如果是版本不夠可以加上-U進行更新升級,如果都不行可以去 python 模塊官網 下載,然后使用 pip install *.whl 進行安裝,要看清對應的版本,否則會報錯

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界面,程式的圖示可要可不要,也可以自己去制作

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)  # 將圖片置于畫布上

在程式里添加文本框,用來放置資料

    # 配置視窗句柄
    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)

程式添加標簽,用來標注

        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)

程式內放置一個CSDN博主二維碼,直達博主主頁,圖片的尺寸是 200x80 ,二維碼由博主制作,內置為博主的主頁鏈接

    # 放置二維碼
    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)  # 將圖片置于畫布上

獲取滑鼠的坐標,通過坐標獲取視窗句柄,然后通過句柄獲取視窗標題、視窗類名、執行緒ID、行程ID和視窗坐標,然后通過行程ID獲取程式名稱、程式路徑、CUP用量和執行緒數,通程序式路徑獲取軟體圖示,這里關聯著滑鼠的bind <B1-Motion>左鍵持續移動,只要滑鼠左鍵持續移動則會執行如下代碼,動一下執行一次

            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)

這個代碼的用處是用來獲取軟體的圖示,通過路徑獲取,并持續保存替換 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

將保存好扽圖片進行加載進來,pictures.png 是軟體的默認圖示,而 icon.png 則是保存下來的圖示進行替換,所以指標指向哪里就會替換為哪一個軟體的圖示,原理就是這樣,只是有一部分的軟體圖示獲取不了或使用不了,會造成軟體內圖示變白

    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

這是能獲取到圖示的

這是獲取不到圖示或使用不了圖示的,只有絕少部分獲取不到或使用不了,不影響軟體的使用,

下面的是按鈕所對應的函式控制元件,用來置頂、取消置頂、顯示頂部、終止程式和打開檔案所在位置,這里要注意的是我采用的taskkill 電腦自帶的終止指令,可以不會支持win7以下的電腦命令,還有就是我這個終止命令會把程式的子程式也終止掉,所以盡量不要去嘗試終止檔案夾和桌面之類的,如果終止掉了螢屏會全白,可以使用【ctrl+alt+delete】進入任務管理器,新建任務,explorer 回車即可恢復,但是有可能你的資料都會被強行關閉,

    # 置頂 通過句柄
    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)

這個是最關鍵的,只有這個控制元件才能起到指標移動是執行命令,canvas_2 指的是在 canvas_2的畫布下可以使用,<B1-Motion> 指的是滑鼠左鍵并移動 待觸發控制元件,showMenu 指的是要執行的命令函式,

# 滑鼠移動控制元件
    canvas_2.bind("<B1-Motion>", showMenu)

廢話不多說,上代碼,

運行不成功的可以要注意,是不是沒有圖片,最上方有資料鏈接,里面包括圖片和源檔案,可以免費下載,代碼都不用復制了

完整代碼:

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()

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/413446.html

標籤:python

上一篇:Pytest系列:csdn最最最詳細,聽不懂你找我。 skip、skipif跳過用例

下一篇:利用Joypy繪制嵴線圖的案例

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 【C++】Microsoft C++、C 和匯編程式檔案

    ......

    uj5u.com 2020-09-10 00:57:23 more
  • 例外宣告

    相比于斷言適用于排除邏輯上不可能存在的狀態,例外通常是用于邏輯上可能發生的錯誤。 例外宣告 Item 1:當函式不可能拋出例外或不能接受拋出例外時,使用noexcept 理由 如果不打算拋出例外的話,程式就會認為無法處理這種錯誤,并且應當盡早終止,如此可以有效地阻止例外的傳播與擴散。 示例 //不可 ......

    uj5u.com 2020-09-10 00:57:27 more
  • Codeforces 1400E Clear the Multiset(貪心 + 分治)

    鏈接:https://codeforces.com/problemset/problem/1400/E 來源:Codeforces 思路:給你一個陣列,現在你可以進行兩種操作,操作1:將一段沒有 0 的區間進行減一的操作,操作2:將 i 位置上的元素歸零。最終問:將這個陣列的全部元素歸零后操作的最少 ......

    uj5u.com 2020-09-10 00:57:30 more
  • UVA11610 【Reverse Prime】

    本人看到此題沒有翻譯,就附帶了一個自己的翻譯版本 思考 這一題,它的第一個要求是找出所有 $7$ 位反向質數及其質因數的個數。 我們應該需要質數篩篩選1~$10^{7}$的所有數,這里就不慢慢介紹了。但是,重讀題,我們突然發現反向質數都是 $7$ 位,而將它反過來后的數字卻是 $6$ 位數,這就說明 ......

    uj5u.com 2020-09-10 00:57:36 more
  • 統計區間素數數量

    1 #pragma GCC optimize(2) 2 #include <bits/stdc++.h> 3 using namespace std; 4 bool isprime[1000000010]; 5 vector<int> prime; 6 inline int getlist(int ......

    uj5u.com 2020-09-10 00:57:47 more
  • C/C++編程筆記:C++中的 const 變數詳解,教你正確認識const用法

    1、C中的const 1、區域const變數存放在堆疊區中,會分配記憶體(也就是說可以通過地址間接修改變數的值)。測驗代碼如下: 運行結果: 2、全域const變數存放在只讀資料段(不能通過地址修改,會發生寫入錯誤), 默認為外部聯編,可以給其他源檔案使用(需要用extern關鍵字修飾) 運行結果: ......

    uj5u.com 2020-09-10 00:58:04 more
  • 【C++犯錯記錄】VS2019 MFC添加資源不懂如何修改資源宏ID

    1. 首先在資源視圖中,添加資源 2. 點擊新添加的資源,復制自動生成的ID 3. 在解決方案資源管理器中找到Resource.h檔案,編輯,使用整個專案搜索和替換的方式快速替換 宏宣告 4. Ctrl+Shift+F 全域搜索,點擊查找全部,然后逐個替換 5. 為什么使用搜索替換而不使用屬性視窗直 ......

    uj5u.com 2020-09-10 00:59:11 more
  • 【C++犯錯記錄】VS2019 MFC不懂的批量添加資源

    1. 打開資源頭檔案Resource.h,在其中預先定義好宏 ID(不清楚其實ID值應該設定多少,可以先新建一個相同的資源項,再在這個資源的ID值的基礎上遞增即可) 2. 在資源視圖中選中專案資源,按F7編輯資源檔案,按 ID 型別 相對路徑的形式添加 資源。(別忘了先把檔案拷貝到專案中的res檔案 ......

    uj5u.com 2020-09-10 01:00:19 more
  • C/C++編程筆記:關于C++的參考型別,專供新手入門使用

    今天要講的是C++中我最喜歡的一個用法——參考,也叫別名。 參考就是給一個變數名取一個變數名,方便我們間接地使用這個變數。我們可以給一個變數創建N個參考,這N + 1個變數共享了同一塊記憶體區域。(參考型別的變數會占用記憶體空間,占用的記憶體空間的大小和指標型別的大小是相同的。雖然參考是一個物件的別名,但 ......

    uj5u.com 2020-09-10 01:00:22 more
  • 【C/C++編程筆記】從頭開始學習C ++:初學者完整指南

    眾所周知,C ++的學習曲線陡峭,但是花時間學習這種語言將為您的職業帶來奇跡,并使您與其他開發人員區分開。您會更輕松地學習新語言,形成真正的解決問題的技能,并在編程的基礎上打下堅實的基礎。 C ++將幫助您養成良好的編程習慣(即清晰一致的編碼風格,在撰寫代碼時注釋代碼,并限制類內部的可見性),并且由 ......

    uj5u.com 2020-09-10 01:00:41 more
最新发布
  • Rust中的智能指標:Box<T> Rc<T> Arc<T> Cell<T> RefCell<T> Weak

    Rust中的智能指標是什么 智能指標(smart pointers)是一類資料結構,是擁有資料所有權和額外功能的指標。是指標的進一步發展 指標(pointer)是一個包含記憶體地址的變數的通用概念。這個地址參考,或 ” 指向”(points at)一些其 他資料 。參考以 & 符號為標志并借用了他們所 ......

    uj5u.com 2023-04-20 07:24:10 more
  • Java的值傳遞和參考傳遞

    值傳遞不會改變本身,參考傳遞(如果傳遞的值需要實體化到堆里)如果發生修改了會改變本身。 1.基本資料型別都是值傳遞 package com.example.basic; public class Test { public static void main(String[] args) { int ......

    uj5u.com 2023-04-20 07:24:04 more
  • [2]SpinalHDL教程——Scala簡單入門

    第一個 Scala 程式 shell里面輸入 $ scala scala> 1 + 1 res0: Int = 2 scala> println("Hello World!") Hello World! 檔案形式 object HelloWorld { /* 這是我的第一個 Scala 程式 * 以 ......

    uj5u.com 2023-04-20 07:23:58 more
  • 理解函式指標和回呼函式

    理解 函式指標 指向函式的指標。比如: 理解函式指標的偽代碼 void (*p)(int type, char *data); // 定義一個函式指標p void func(int type, char *data); // 宣告一個函式func p = func; // 將指標p指向函式func ......

    uj5u.com 2023-04-20 07:23:52 more
  • Django筆記二十五之資料庫函式之日期函式

    本文首發于公眾號:Hunter后端 原文鏈接:Django筆記二十五之資料庫函式之日期函式 日期函式主要介紹兩個大類,Extract() 和 Trunc() Extract() 函式作用是提取日期,比如我們可以提取一個日期欄位的年份,月份,日等資料 Trunc() 的作用則是截取,比如 2022-0 ......

    uj5u.com 2023-04-20 07:23:45 more
  • 一天吃透JVM面試八股文

    什么是JVM? JVM,全稱Java Virtual Machine(Java虛擬機),是通過在實際的計算機上仿真模擬各種計算機功能來實作的。由一套位元組碼指令集、一組暫存器、一個堆疊、一個垃圾回收堆和一個存盤方法域等組成。JVM屏蔽了與作業系統平臺相關的資訊,使得Java程式只需要生成在Java虛擬機 ......

    uj5u.com 2023-04-20 07:23:31 more
  • 使用Java接入小程式訂閱訊息!

    更新完微信服務號的模板訊息之后,我又趕緊把微信小程式的訂閱訊息給實作了!之前我一直以為微信小程式也是要企業才能申請,沒想到小程式個人就能申請。 訊息推送平臺🔥推送下發【郵件】【短信】【微信服務號】【微信小程式】【企業微信】【釘釘】等訊息型別。 https://gitee.com/zhongfuch ......

    uj5u.com 2023-04-20 07:22:59 more
  • java -- 緩沖流、轉換流、序列化流

    緩沖流 緩沖流, 也叫高效流, 按照資料型別分類: 位元組緩沖流:BufferedInputStream,BufferedOutputStream 字符緩沖流:BufferedReader,BufferedWriter 緩沖流的基本原理,是在創建流物件時,會創建一個內置的默認大小的緩沖區陣列,通過緩沖 ......

    uj5u.com 2023-04-20 07:22:49 more
  • Java-SpringBoot-Range請求頭設定實作視頻分段傳輸

    老實說,人太懶了,現在基本都不喜歡寫筆記了,但是網上有關Range請求頭的文章都太水了 下面是抄的一段StackOverflow的代碼...自己大修改過的,寫的注釋挺全的,應該直接看得懂,就不解釋了 寫的不好...只是希望能給視頻網站開發的新手一點點幫助吧. 業務場景:視頻分段傳輸、視頻多段傳輸(理 ......

    uj5u.com 2023-04-20 07:22:42 more
  • Windows 10開發教程_編程入門自學教程_菜鳥教程-免費教程分享

    教程簡介 Windows 10開發入門教程 - 從簡單的步驟了解Windows 10開發,從基本到高級概念,包括簡介,UWP,第一個應用程式,商店,XAML控制元件,資料系結,XAML性能,自適應設計,自適應UI,自適應代碼,檔案管理,SQLite資料庫,應用程式到應用程式通信,應用程式本地化,應用程式 ......

    uj5u.com 2023-04-20 07:22:35 more