用python3 返回鼠标位置的实现方法(带界面)

作者:叫我彪哥呀 时间:2021-07-17 15:11:40 

点击获取后,返回2s后的鼠标位置,显示在文本框

(需要用pip命令安装所需的的库)

(pip install 模块名

比如 安装pyautogui 模块

在cmd里面输入: pip install pyautogui)

用python3 返回鼠标位置的实现方法(带界面)


#!/usr/bin/python3
# -*- coding: UTF-8 -*-

import time
import pyautogui as pag
import tkinter

def get():
 po.delete(0,tkinter.END)
time.sleep(2) #几秒后返回位置
 x , y = pag.position()
 po.insert(0,str(x)+','+str(y))

root = tkinter.Tk()
tip = tkinter.Label(root,text="返回点击获取2s后的光标位置")
tip.grid(row=0)
po = tkinter.Entry(root)
po.grid(row=1)
do = tkinter.Button(root,text="获取",command=get) #点击获取位置
do.grid(row=2)

root.mainloop()

闲得无聊把时间调成可改了,但是其中一个if莫名其妙运行不了,求大神解释QAQ

由于布局问题,若要调整窗口位置,请拖动左上角


#!/usr/bin/python3
# -*- coding: UTF-8 -*-

import time
import pyautogui as pag
import tkinter

mytime = 2

#判断时间是否合法
def safe():
text = getmytime.get();
#小数点个数
point = 0
if(text==""):
return False
for i in text:
if(i>='0' and i<='9'and point<2):
continue
elif(i=='.'):
point = point + 1
else:
return False
return True
def get():
global mytime
if(safe()):
mytime = float(getmytime.get())

#不知道为何下面的这个if没用
if(mytime>7.0):
showpos.delete(0,tkinter.END)
showpos.insert(0,"请耐心等候")

time.sleep(mytime) #几秒后返回位置
x , y = pag.position()
showpos.delete(0,tkinter.END)
showpos.insert(0,str(x)+','+str(y))
else:
showpos.delete(0,tkinter.END)
showpos.insert(0,"输入非法哟~")

root = tkinter.Tk()
root.resizable(0,0)

tip1 = tkinter.Label(root,text="点击按钮获取")
tip1.place(relx=0.1,rely=0.1)
getmytime = tkinter.Entry(root,width=3)
getmytime.place(relx=0.6,rely=0.1)
getmytime.insert(0,str(mytime))
tip2 = tkinter.Label(root,text="s后的")
tip2.place(relx=0.8,rely=0.1)

tip3 = tkinter.Label(root,text="光标位置:")
tip3.place(relx=0.1,rely=0.3)
showpos = tkinter.Entry(root,width=10)
showpos.place(relx=0.5,rely=0.3)
do = tkinter.Button(root,text="按钮",command=get) #点击获取位置
do.place(relx=0.8,rely=0.6)

root.mainloop()

来源:https://blog.csdn.net/qq_34438779/article/details/81317452

标签:python3,鼠标,位置
0
投稿

猜你喜欢

  • Python 使用requests模块发送GET和POST请求的实现代码

    2023-07-19 23:19:27
  • python3 字符串str和bytes相互转换

    2023-03-31 09:12:47
  • php中-> 、=>、::、$this->四种常见符号使用方法技巧

    2023-05-30 07:46:24
  • python开发之IDEL(Python GUI)的使用方法图文详解

    2023-09-15 23:22:42
  • python 读取文件并替换字段的实例

    2022-10-18 05:12:21
  • 防采集,几种觉得有用的防采集方法

    2009-09-03 13:30:00
  • Python进程的通信Queue、Pipe实例分析

    2021-11-22 13:50:44
  • ASP同一站点下gb2312和utf-8页面传递参数乱码的终极解决方法

    2011-02-20 11:00:00
  • python+selenium实现登录账户后自动点击的示例

    2021-07-26 05:40:21
  • Oracle 数据 使用游标

    2009-07-02 12:14:00
  • mysql 修改表结构 判断并添加column

    2010-10-25 20:07:00
  • 通过python实现弹窗广告拦截过程详解

    2022-04-12 09:21:31
  • 使用PHP批量生成随机用户名

    2023-07-22 13:10:10
  • wdcp添加tomcat,同时支持php和java教程

    2023-10-09 10:39:38
  • Python代码模拟CPU工作原理

    2023-08-04 15:23:49
  • DD_belatedPNG,解决IE6不支持PNG绝佳方案

    2009-04-27 16:30:00
  • 网页特效文字之—压纹字

    2023-06-26 19:30:06
  • phpstudy apache开启ssi使用详解

    2023-05-25 08:04:44
  • asp函数转换xml中的实体字符[转义符]

    2008-10-16 17:07:00
  • Python中的装饰器使用

    2023-05-25 13:14:09
  • asp之家 网络编程 m.aspxhome.com