用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)文章
pycharm顯示遠(yuǎn)程圖片的實(shí)現(xiàn)
這篇文章主要介紹了pycharm顯示遠(yuǎn)程圖片的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-11-11
利用Python實(shí)現(xiàn)定時(shí)程序的方法
在 Python 中,如何定義一個(gè)定時(shí)器函數(shù)呢?本文主要介紹了2種方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-07-07
PyQt4 treewidget 選擇改變顏色,并設(shè)置可編輯的方法
今天小編就為大家分享一篇PyQt4 treewidget 選擇改變顏色,并設(shè)置可編輯的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-06-06
使用python實(shí)現(xiàn)一個(gè)簡(jiǎn)單的圖片爬蟲
在本文中,我們將學(xué)習(xí)如何使用Python創(chuàng)建一個(gè)簡(jiǎn)單的圖片爬蟲,我們將利用requests庫來發(fā)送HTTP請(qǐng)求,BeautifulSoup庫來解析HTML頁面,以及os和shutil庫來下載和保存圖片,通過這個(gè)教程,你將學(xué)會(huì)如何爬取網(wǎng)頁上的圖片并保存到本地,需要的朋友可以參考下2024-02-02
用Python實(shí)現(xiàn)一個(gè)簡(jiǎn)單的用戶系統(tǒng)
大家好,本篇文章主要講的是用Python實(shí)現(xiàn)一個(gè)簡(jiǎn)單的用戶系統(tǒng),感興趣的同學(xué)趕快來看一看吧,對(duì)你有幫助的話記得收藏一下2022-01-01

