日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

用python3 返回鼠標位置的實現方法(帶界面)

系統 1816 0

點擊獲取后,返回2s后的鼠標位置,顯示在文本框

(需要用pip命令安裝所需的的庫)

(pip install 模塊名

比如 安裝pyautogui 模塊

在cmd里面輸入: pip install pyautogui)

用python3 返回鼠標位置的實現方法(帶界面)_第1張圖片

            
#!/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()

          

以上這篇用python3 返回鼠標位置的實現方法(帶界面)就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持腳本之家。


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 沙坪坝区| 江西省| 浮梁县| 安康市| 铜山县| 会昌县| 梁平县| 哈尔滨市| 江西省| 武义县| 阜康市| 铜鼓县| 丰都县| 稷山县| 娄烦县| 河津市| 宁都县| 镇雄县| 中山市| 聂荣县| 镇平县| 安庆市| 罗定市| 寻乌县| 尖扎县| 紫阳县| 西乡县| 建昌县| 鄂尔多斯市| 微博| 三明市| 南郑县| 高阳县| 长治县| 宜川县| 佳木斯市| 灌云县| 丹棱县| 淮北市| 尚志市| 元谋县|