博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
用python3 返回鼠标位置(带界面)
阅读量:2048 次
发布时间:2019-04-28

本文共 1772 字,大约阅读时间需要 5 分钟。

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

(需要用pip命令安装所需的的库)
(pip install 模块名
比如 安装pyautogui 模块
在cmd里面输入: pip install pyautogui)
这里写图片描述

#!/usr/bin/python3# -*- coding: UTF-8 -*-import timeimport pyautogui as pagimport tkinterdef 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 timeimport pyautogui as pagimport tkintermytime = 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 Truedef 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()
你可能感兴趣的文章
Leetcode C++《每日一题》20200707 112. 路径总和
查看>>
云原生 第十一章 应用健康
查看>>
Leetcode C++ 《第202场周赛》
查看>>
云原生 第十二章 可观测性:监控与日志
查看>>
Leetcode C++ 《第203场周赛》
查看>>
云原生 第十三章 Kubernetes网络概念及策略控制
查看>>
《redis设计与实现》 第一部分:数据结构与对象 || 读书笔记
查看>>
《redis设计与实现》 第二部分(第9-11章):单机数据库的实现
查看>>
算法工程师 面经2019年5月
查看>>
搜索架构师 一面面经2019年6月
查看>>
稻草人手记
查看>>
第一次kaggle比赛 回顾篇
查看>>
leetcode 50. Pow(x, n)
查看>>
leetcode 130. Surrounded Regions
查看>>
【托业】【全真题库】TEST2-语法题
查看>>
博客文格式优化
查看>>
【托业】【新托业全真模拟】疑难语法题知识点总结(01~05)
查看>>
【SQL】group by 和order by 的区别。
查看>>
【F12】谷歌浏览器--前台效果可以在不访问服务器的前提下直接改样式看效果是否是预期值。...
查看>>
【Python】详解Python多线程Selenium跨浏览器测试
查看>>