python 五子棋如何獲得鼠標(biāo)點(diǎn)擊坐標(biāo)
這篇文章主要介紹了python 五子棋如何獲得鼠標(biāo)點(diǎn)擊坐標(biāo),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
點(diǎn)坐標(biāo)的取自:
from tkinter import *
root=Tk()
#創(chuàng)建一個(gè)框架,在這個(gè)框架中響應(yīng)事件
frame=Frame(root,width=200,height=200)
def callBackLeft(event):
print("相對(duì)于應(yīng)用程序左上角的位置,左鍵點(diǎn)擊的位置是",event.x,event.y)
print("相對(duì)于屏幕左上角的位置,左鍵點(diǎn)擊的位置是",event.x_root,event.y_root)
def callBackRight(event):
print("右鍵點(diǎn)擊的位置是",event.x,event.y)
print("右鍵點(diǎn)擊的位置是",event.x_root,event.y_root)
frame.bind("<Button-1>",callBackLeft)
frame.bind("<Button-3>",callBackRight)
frame.pack()
mainloop()
執(zhí)行后 結(jié)果如圖:

對(duì)坐標(biāo)進(jìn)行 處理和過(guò)濾得到 具體坐標(biāo)
from tkinter import *
root = Tk()
size = 16
def piant(event):
if event.x % 30 > 15:
event.x = event.x // 30 + 1
else:
event.x = event.x // 30
if event.y % 30 > 15:
event.y = event.y // 30 + 1
else:
event.y = event.y // 30
# 邊緣檢測(cè)
if event.x > size:
event.x = size
if event.y > size:
event.y = size
if event.x < 1:
event.x = 1
if event.y < 1:
event.y = 1
print("x坐標(biāo):%d,y坐標(biāo):%d"%(event.x,event.y))
canvas = Canvas(root, width=500, height=500)
canvas.pack(expand=YES, fill=BOTH)
canvas.bind("<Button-1>",piant)
canvas.pack()
#畫(huà)豎線
for num in range(1, 17):
canvas.create_line(num * 30, 30,
num * 30, 480,
width=2)
#畫(huà)橫線
for num in range(1, 17):
canvas.create_line(30, num * 30,
480, num * 30,
width=2)
root.mainloop()
執(zhí)行后 結(jié)果如圖:

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- python點(diǎn)擊鼠標(biāo)獲取坐標(biāo)(Graphics)
- python 讀取鼠標(biāo)點(diǎn)擊坐標(biāo)的實(shí)例
- Python鼠標(biāo)事件及坐標(biāo)獲取窗口和屏幕坐標(biāo)
- python opencv鼠標(biāo)事件實(shí)現(xiàn)畫(huà)框圈定目標(biāo)獲取坐標(biāo)信息
- Python2.7:使用Pyhook模塊監(jiān)聽(tīng)鼠標(biāo)鍵盤(pán)事件-獲取坐標(biāo)實(shí)例
- 基于python實(shí)現(xiàn)鼠標(biāo)實(shí)時(shí)坐標(biāo)監(jiān)測(cè)
- 一文詳解如何使用Python實(shí)時(shí)輸出鼠標(biāo)坐標(biāo)
相關(guān)文章
Python實(shí)現(xiàn)動(dòng)態(tài)條形圖繪制的示例代碼
這篇文章主要為大家詳細(xì)介紹了如何利用Python語(yǔ)言實(shí)現(xiàn)動(dòng)態(tài)條形圖的繪制,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2022-08-08
Python內(nèi)置數(shù)據(jù)類型list各方法的性能測(cè)試過(guò)程解析
這篇文章主要介紹了Python內(nèi)置數(shù)據(jù)類型list各方法的性能測(cè)試過(guò)程解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-01-01
Playwright元素截圖并保存至allure的實(shí)現(xiàn)示例
在UI自動(dòng)化測(cè)試中,我們經(jīng)常需要獲取屏幕截圖,本文就介紹一下Playwright元素截圖并保存至allure的實(shí)現(xiàn)示例,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-12-12
詳解Python中 __get__和__getattr__和__getattribute__的區(qū)別
__get__、__getattr__、__getattribute都是訪問(wèn)屬性的方法,但作用不太相同,這里我們就來(lái)詳解Python中 __get__和__getattr__和__getattribute__的區(qū)別:2016-06-06
python3實(shí)現(xiàn)繪制二維點(diǎn)圖
今天小編就為大家分享一篇python3實(shí)現(xiàn)繪制二維點(diǎn)圖,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-12-12
使用 Python 實(shí)現(xiàn)微信群友統(tǒng)計(jì)器的思路詳解
這篇文章主要介紹了使用 Python 實(shí)現(xiàn)微信群友統(tǒng)計(jì)器的思路詳解,需要的朋友可以參考下2018-09-09

