點(diǎn)擊獲取后,返回2s后的鼠標(biāo)位置,顯示在文本框
(需要用pip命令安裝所需的的庫(kù))
(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()
閑得無(wú)聊把時(shí)間調(diào)成可改了,但是其中一個(gè)if莫名其妙運(yùn)行不了,求大神解釋QAQ
由于布局問(wèn)題,若要調(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沒(méi)用 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è)參考,也希望大家多多支持腳本之家。
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號(hào)聯(lián)系: 360901061
您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對(duì)您有幫助就好】元
