第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何在 tkinter 窗口上顯示實(shí)時(shí)鼠標(biāo)位置

如何在 tkinter 窗口上顯示實(shí)時(shí)鼠標(biāo)位置

慕萊塢森 2023-06-06 15:07:33
我想知道是否有辦法在 tkinter 窗口上繼續(xù)顯示實(shí)時(shí)鼠標(biāo)位置。我知道如何找到鼠標(biāo)坐標(biāo)。x, y = win32api.GetCursorPos() mousecords = Label(self.root, text='x : ' + str(x) + ', y : ' + str(y)) mousecords.place(x=0, y=0)但是我需要標(biāo)簽在鼠標(biāo)移動(dòng)時(shí)不斷更新。幫助將不勝感激 謝謝!
查看完整描述

2 回答

?
慕容3067478

TA貢獻(xiàn)1773條經(jīng)驗(yàn) 獲得超3個(gè)贊

這只會(huì)在Label鼠標(biāo)位于 tkinter 窗口內(nèi)時(shí)更新:


無(wú)需使用 win32api,tkinter 內(nèi)置了它。我們可以將一個(gè)函數(shù)綁定到root的<Motion>鍵上,并使用給定的位置參數(shù)event來(lái)檢索鼠標(biāo)的坐標(biāo)。


from tkinter import Tk, Label


root = Tk()

label = Label(root)

label.pack()

root.bind("<Motion>", lambda event: label.configure(text=f"{event.x}, {event.y}"))

root.mainloop()


查看完整回答
反對(duì) 回復(fù) 2023-06-06
?
慕婉清6462132

TA貢獻(xiàn)1804條經(jīng)驗(yàn) 獲得超2個(gè)贊

您可以使用它after()來(lái)定期獲取鼠標(biāo)坐標(biāo)并更新標(biāo)簽。


下面是一個(gè)例子:


import tkinter as tk

import win32api


root = tk.Tk()


mousecords = tk.Label(root)

mousecords.place(x=0, y=0)


def show_mouse_pos():

    x, y = win32api.GetCursorPos()

    #x, y = mousecords.winfo_pointerxy() # you can also use tkinter to get the mouse coords

    mousecords.config(text=f'x : {x}, y : {y}')

    mousecords.after(50, show_mouse_pos) # call again 50ms later


show_mouse_pos() # start the update task

root.mainloop()


查看完整回答
反對(duì) 回復(fù) 2023-06-06
  • 2 回答
  • 0 關(guān)注
  • 250 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)