卖打火机的小男孩 发表于 2023-2-28 09:48:51

通过手势识别上下左右滑动

先看看效果!
https://www.bilibili.com/video/BV1pY411r7Jx/?buvid=XXF3D58F209E269A13ACA9CDB46D9FD108C2A&is_story_h5=false&mid=W%2F52TcRurwVc3RCf3%2FP0fg%3D%3D&plat_id=462&share_from=ugc&share_medium=android&share_plat=android&share_source=WEIXIN&share_tag=s_i×tamp=1677547665&unique_k=joWUGux&up_id=14548080

直接上代码
不清楚的留言交流
import time
from unihiker import GUI# 导入包

gui = GUI()# 实例化GUI类

img_image2 = gui.draw_image(x=0, y=0, image='4.png')


def mouse_move(x, y):
    print("坐标:x={},y={}".format(x, y))
    if compare(x, 90, 170) and compare(y, 80, 110):
      img_image2.config(image="1.png")
    elif compare(x, 35, 70) and compare(y, 110, 185):
      img_image2.config(image="2.png")
    elif compare(x, 120, 230) and compare(y, 200, 240):
      img_image2.config(image="4.png")
    elif compare(x, 169, 210) and compare(y, 110, 185):
      img_image2.config(image="3.png")


def compare(val, min, max):
    if val in range(min, max + 1):
      return True
    else:
      return False


xx = 0
yy = 0

def press(x):
    global xx
    xx =
    # print(xx)


def release(y):
    yy =
    temp = yy - xx
    temp1 = yy - xx
    if temp > 30:
      # print("右滑")
      img_image2.config(image="3.png")
    if temp < -30:
      # print("左滑")
      img_image2.config(image="2.png")
    if temp1 > 30:
      # print("下滑")
      img_image2.config(image="4.png")
    if temp1 < -30:
      # print("上滑")
      img_image2.config(image="1.png")


#   print(temp1)

# 通过点击方式切换按钮
# gui.on_mouse_move(mouse_move)

# 通过手势切换按钮
gui.master.bind('<Button-1>', press)# 鼠标左键按下
gui.master.bind("<ButtonRelease>", release)# 鼠标左键释放

while True:
    # 增加等待,防止程序退出和卡住
    time.sleep(1)





Forgotten 发表于 2023-3-1 11:17:41

{:6_213:}{:6_213:}{:6_213:}

ASH腻 发表于 2023-3-6 19:12:10

wow 效果不错
页: [1]
查看完整版本: 通过手势识别上下左右滑动