用python3 返回鼠標(biāo)位置的實(shí)現(xiàn)方法(帶界面)
點(diǎn)擊獲取后,返回2s后的鼠標(biāo)位置,顯示在文本框
(需要用pip命令安裝所需的的庫)
(pip install 模塊名
比如 安裝pyautogui 模塊
在cmd里面輸入: pip install pyautogui)
#!/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="返回點(diǎn)擊獲取2s后的光標(biāo)位置") tip.grid(row=0) po = tkinter.Entry(root) po.grid(row=1) do = tkinter.Button(root,text="獲取",command=get) #點(diǎn)擊獲取位置 do.grid(row=2) root.mainloop()
閑得無聊把時(shí)間調(diào)成可改了,但是其中一個(gè)if莫名其妙運(yùn)行不了,求大神解釋QAQ
由于布局問題,若要調(diào)整窗口位置,請(qǐng)拖動(dòng)左上角
#!/usr/bin/python3 # -*- coding: UTF-8 -*- import time import pyautogui as pag import tkinter mytime = 2 #判斷時(shí)間是否合法 def safe(): text = getmytime.get(); #小數(shù)點(diǎn)個(gè)數(shù) 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()) #不知道為何下面的這個(gè)if沒用 if(mytime>7.0): showpos.delete(0,tkinter.END) showpos.insert(0,"請(qǐng)耐心等候") 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="點(diǎn)擊按鈕獲取") 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="光標(biāo)位置:") 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) #點(diǎn)擊獲取位置 do.place(relx=0.8,rely=0.6) root.mainloop()
以上這篇用python3 返回鼠標(biāo)位置的實(shí)現(xiàn)方法(帶界面)就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
在Python的Django框架中創(chuàng)建和使用模版
這篇文章主要介紹了在Python的Django框架中創(chuàng)建和使用模版的方法,包括使用manage.py shell來幫助設(shè)置模版的方法,需要的朋友可以參考下2015-07-07python中csv文件數(shù)據(jù)顏色設(shè)置方式
這篇文章主要介紹了python中csv文件數(shù)據(jù)顏色設(shè)置方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-02-02NumPy隨機(jī)數(shù)據(jù)分布與Seaborn可視化詳解
數(shù)據(jù)分布是指數(shù)據(jù)集中所有可能值出現(xiàn)的頻率,并用概率來表示,它描述了數(shù)據(jù)取值的可能性,Seaborn 是一個(gè)基于 Matplotlib 的 Python 數(shù)據(jù)可視化庫,用于創(chuàng)建統(tǒng)計(jì)圖表,本文就給大家詳細(xì)的介紹一下NumPy隨機(jī)數(shù)據(jù)分布與Seaborn可視化,需要的朋友可以參考下2024-05-05Python測(cè)試開源工具splinter安裝與使用教程
Splinter是一個(gè)使用Python測(cè)試Web應(yīng)用程序的開源工具,可以自動(dòng)化瀏覽器操作,使用Splinter可以使用pyhton腳本來實(shí)現(xiàn),具體安裝及操作方法跟隨小編一起看看吧2021-07-07Python中關(guān)于面向?qū)ο蟾拍畹脑敿?xì)講解
要了解面向?qū)ο笪覀兛隙ㄐ枰戎缹?duì)象到底是什么玩意兒。關(guān)于對(duì)象的理解很簡(jiǎn)單,在我們的身邊,每一種事物的存在都是一種對(duì)象??偨Y(jié)為一句話也就是:對(duì)象就是事物存在的實(shí)體2021-10-10解決pyCharm中 module 調(diào)用失敗的問題
今天小編就為大家分享一篇解決pyCharm中 module 調(diào)用失敗的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-02-02詳解Python如何使用Netmiko進(jìn)行文件傳輸
Netmiko是一個(gè)用于連接和管理各種網(wǎng)絡(luò)設(shè)備的Python庫,它是Paramiko的一個(gè)擴(kuò)展。本文就來講講如何利用Netmiko實(shí)現(xiàn)文件傳輸功能吧2023-05-05