Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6786907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:18:05+00:00 2026-05-26T17:18:05+00:00

I want to track my mouse-position and show that in a tiny window. For

  • 0

I want to track my mouse-position and show that in a tiny window.
For that, I created this piece of code:

#! /usr/bin/python

from Tkinter import *
from Xlib import display

def mousepos():
    data = display.Display().screen().root.query_pointer()._data
    return data["root_x"], data["root_y"]

root = Tk()
strl = "mouse at {0}".format(mousepos())
lab = Label(root,text=strl)
lab.pack()
root.title("Mouseposition")

root.mainloop()

This little script shows the mouse-position on startup but doesn’t refresh it on mouse-movement. I don’t get behind it (did I say that I’m new to python?).
I think I have to use an event from Xlib that tells my script when the mouse is moving…

How do I refresh my mouse-position?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T17:18:05+00:00Added an answer on May 26, 2026 at 5:18 pm
    1. Use root.after to call update periodically.
    2. Use strl = tk.StringVar() and tk.Label(...,textvariable=strl) to
      allow the Label text to change.
    3. Call strl.set() to change the Label text.
    4. A default value for screenroot equal to display.Display().screen().root was added
      to mousepos so that most of that long chain of function calls are
      not repeated every time mousepos is called. Calling mousepos() without any arguments will continue to work as usual.

    import Tkinter as tk
    import Xlib.display as display
    
    def mousepos(screenroot=display.Display().screen().root):
        pointer = screenroot.query_pointer()
        data = pointer._data
        return data["root_x"], data["root_y"]
    
    def update():
        strl.set("mouse at {0}".format(mousepos()))
        root.after(100, update)
    
    root = tk.Tk()
    strl = tk.StringVar()
    lab = tk.Label(root,textvariable=strl)
    lab.pack()
    root.after(100, update)
    root.title("Mouseposition")
    root.mainloop()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a robot that uses an optical mouse as a position track. Basically,
I want to track how much traffic I'm getting on an RSS feed that
How to track the mouse position on the screen regardless of application.i.e. Whenever the
I have a function that tracks the user's mouse to show them visually where
I'm new at using actionListener and mouselistner . I want to track the Mouse
This should be typically easy, I want to perform tracking of mouse movements. I'm
I am using the mouseMoveEvent to track the position of the mouse cursor in
We want to track the time taken by a web service call between a
I want to track incoming traffic to a website from campaigns. A campain link
I want to track a person's movement on mapview in my iphone. I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.