python中显示功能的实现,如何用python 实现老板键功能

主要实现目标:为多个指定的程序实现统一的老板键,一键隐藏多个指定的应用程序的窗口及任务栏。

1.获取所有顶层窗口

import win32gui

hwnd_title = dict()

def get_all_hwnd(hwnd, mouse):

# 判断句柄是否为窗口、窗口是否允许输入、窗口是否可视

if win32gui.IsWindow(hwnd) and win32gui.IsWindowEnabled(hwnd) and win32gui.IsWindowVisible(hwnd):

hwnd_title.update({hwnd: win32gui.GetWindowText(hwnd)})

# EnumWindows枚举所有顶层窗口

win32gui.EnumWindows(get_all_hwnd, 0)

# 打印出所有窗口名不为空的窗口

for key in list(hwnd_title):

if hwnd_title[key] is "":

del hwnd_title[key]

e09c6cf427c6ccb0d8232b0938a98435.png

2.手动选择需要设置老板键的程序

import tkinter as tk

root = tk.Tk()

root.geometry("800x400")

# 列表显示所有顶层窗口

listBox = tk.Listbox(root, selectmode="multiple")

listBox.pack(side="left", expand="yes", fill="both")

for i, j in hwnd_title.items():

if j is not "":

listBox.insert("end", str(i) + ":" + j)

bt = tk.Button(root, text='选择')

bt.pack()

root.mainloop()

d8eea7f6768e548ca281c125a5990567.png

3.隐藏或显示选中程序

# 通过GetWindowRect方法获取隐藏前的窗口位置及尺寸信息

left, top, right, bottom = win32gui.GetWindowRect()

def close_windows(aimLists):

for k in aimLists:

# 隐藏程序窗口

win32gui.SetWindowPos(lists[k][0], 0, 0, 0, 0, 0, SWP_HIDEWINDOW)

def open_windows(aimLists):

for k in aimLists:

# 显示程序窗口

t = lists[k]

win32gui.SetWindowPos(t['hwnd'], 0, t['left'], t['top'], t['right'] - t['left'], t['bottom'] - t['top'],

SWP_SHOWWINDOW)

4.设置显示隐藏快捷键

这里设置F7显示,F8隐藏,F12中止

import PyHook3

import pythoncom

def onKeyboardEvent(event):

key = event.Key

if key == "F7":

close_windows(aimLists)

if key == "F8":

open_windows(aimLists)

if key == "F12":

win32gui.PostQuitMessage(0)

return True

hm = PyHook3.HookManager()

hm.KeyDown = onKeyboardEvent

hm.HookKeyboard()

# 开启监听

pythoncom.PumpMessages()

5.最终效果

0f919a3f0eff23b0adb65c3e91485dfb.gif

以上就是python 老板键功能的实现步骤的详细内容,更多关于python 老板键功能的资料请关注脚本之家其它相关文章!

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值