Skip to main content
ubuntuask.com

Back to all posts

How to Add A Mouse Click Position to A List In Tkinter?

Published on
4 min read
How to Add A Mouse Click Position to A List In Tkinter? image

Best Mouse Click Event Tools to Buy in October 2025

1 Cloudeck Mouse Jiggler Undetectable, USB Mover, Gaming Automatic Continuous Click Device, Plug & Play, Simulate Mouse Pointer Movement to Prevent PC Sleep

Cloudeck Mouse Jiggler Undetectable, USB Mover, Gaming Automatic Continuous Click Device, Plug & Play, Simulate Mouse Pointer Movement to Prevent PC Sleep

  • 2-IN-1 FUNCTIONALITY: SIMULATES MOUSE MOVEMENT & AUTO-CLICKS EASILY.

  • IT DEPARTMENT PROOF: OPERATES UNDETECTED; KEEPS YOUR PC AWAKE SAFELY.

  • PLUG & PLAY: INSTANT SETUP; NO DRIVERS OR SOFTWARE REQUIRED TO USE.

BUY & SAVE
$13.98 $19.99
Save 30%
Cloudeck Mouse Jiggler Undetectable, USB Mover, Gaming Automatic Continuous Click Device, Plug & Play, Simulate Mouse Pointer Movement to Prevent PC Sleep
2 TECKNET Wireless Mouse Jiggler, USB-C Rechargeable Mouse, Silent Mouse Quiet Click, Build-in Mouse Mover, 6400 DPI Ergonomic Mouse, 2.4G Cordless Computer Mice for Mac, Laptop, Desktop, PC

TECKNET Wireless Mouse Jiggler, USB-C Rechargeable Mouse, Silent Mouse Quiet Click, Build-in Mouse Mover, 6400 DPI Ergonomic Mouse, 2.4G Cordless Computer Mice for Mac, Laptop, Desktop, PC

  • STAY ACTIVE: BUILT-IN JIGGLER KEEPS YOUR SCREEN AWAKE EFFORTLESSLY

  • CHARGE IN 2 HOURS: ENJOY 90 DAYS OF UNINTERRUPTED PRODUCTIVITY

  • SILENT OPERATION: WORK DISCREETLY IN ANY ENVIRONMENT, DAY OR NIGHT

BUY & SAVE
$15.99 $17.99
Save 11%
TECKNET Wireless Mouse Jiggler, USB-C Rechargeable Mouse, Silent Mouse Quiet Click, Build-in Mouse Mover, 6400 DPI Ergonomic Mouse, 2.4G Cordless Computer Mice for Mac, Laptop, Desktop, PC
3 Logitech M330 SILENT Wireless Mouse, 2.4GHz with USB Receiver, Optical Tracking, Quiet & Lightweight, Long Battery Life, for PC, Mac, Laptop, Chromebook - Black

Logitech M330 SILENT Wireless Mouse, 2.4GHz with USB Receiver, Optical Tracking, Quiet & Lightweight, Long Battery Life, for PC, Mac, Laptop, Chromebook - Black

  • QUIET EFFICIENCY: ENJOY OVER 90% LESS CLICKING NOISE FOR PEACE.

  • ERGONOMIC COMFORT: DESIGNED FOR RIGHT-HANDED USERS FOR ALL-DAY USE.

  • LONG BATTERY LIFE: UP TO 18 MONTHS-FOCUS MORE, CHANGE BATTERIES LESS.

BUY & SAVE
$18.99 $22.99
Save 17%
Logitech M330 SILENT Wireless Mouse, 2.4GHz with USB Receiver, Optical Tracking, Quiet & Lightweight, Long Battery Life, for PC, Mac, Laptop, Chromebook - Black
4 Logitech M240 Silent Bluetooth Mouse, Wireless, Compact, Portable, Smooth Tracking, 18-Month Battery, for Windows, macOS, ChromeOS, Compatible with PC, Mac, Laptop, Tablets - Graphite

Logitech M240 Silent Bluetooth Mouse, Wireless, Compact, Portable, Smooth Tracking, 18-Month Battery, for Windows, macOS, ChromeOS, Compatible with PC, Mac, Laptop, Tablets - Graphite

  • EFFORTLESS BLUETOOTH CONNECTION-NO DONGLES OR PORTS NEEDED!
  • 90% QUIETER CLICKS FOR ULTIMATE FOCUS IN ANY ENVIRONMENT.
  • TRAVEL-FRIENDLY DESIGN WITH 18-MONTH BATTERY LIFE-STAY PRODUCTIVE!
BUY & SAVE
$17.99 $22.99
Save 22%
Logitech M240 Silent Bluetooth Mouse, Wireless, Compact, Portable, Smooth Tracking, 18-Month Battery, for Windows, macOS, ChromeOS, Compatible with PC, Mac, Laptop, Tablets - Graphite
5 TECKNET Ergonomic Mouse, Wireless Bluetooth Vertical Mouse, 4800 DPI Optical Tracking, 6 Adjustable DPI, Quiet Clicks, 2.4GHz with USB A Receiver, 12 Months Battery, 6 Buttons, Wide Compatibility

TECKNET Ergonomic Mouse, Wireless Bluetooth Vertical Mouse, 4800 DPI Optical Tracking, 6 Adjustable DPI, Quiet Clicks, 2.4GHz with USB A Receiver, 12 Months Battery, 6 Buttons, Wide Compatibility

  • SEAMLESS DEVICE SWITCHING: CONNECT UP TO 3 DEVICES EFFORTLESSLY!
  • CUSTOMIZABLE DPI LEVELS: 6 SETTINGS FOR PRECISION ON ANY SURFACE.
  • ERGONOMIC & SILENT: COMFORT AND QUIET CLICKS FOR FOCUSED WORK SESSIONS.
BUY & SAVE
$27.99 $29.99
Save 7%
TECKNET Ergonomic Mouse, Wireless Bluetooth Vertical Mouse, 4800 DPI Optical Tracking, 6 Adjustable DPI, Quiet Clicks, 2.4GHz with USB A Receiver, 12 Months Battery, 6 Buttons, Wide Compatibility
6 Logitech Ergo M575S Wireless Trackball Mouse, Wireless Ergonomic Mouse with Bluetooth and Encrypted Dongle, Comfortable Thumb Control, Precise and Smooth Tracking, for PC/Mac - Black Silver Ball

Logitech Ergo M575S Wireless Trackball Mouse, Wireless Ergonomic Mouse with Bluetooth and Encrypted Dongle, Comfortable Thumb Control, Precise and Smooth Tracking, for PC/Mac - Black Silver Ball

  • EXPERIENCE ALL-DAY COMFORT WITH LESS MUSCLE STRAIN (25% IMPROVED).
  • CUSTOMIZE YOUR CONTROL WITH 3 BUTTONS AND SMART ACTIONS OPTIONS.
  • SILENT CLICKS AND COMPACT DESIGN SAVE SPACE FOR ANY SETUP.
BUY & SAVE
$49.99
Logitech Ergo M575S Wireless Trackball Mouse, Wireless Ergonomic Mouse with Bluetooth and Encrypted Dongle, Comfortable Thumb Control, Precise and Smooth Tracking, for PC/Mac - Black Silver Ball
7 Logitech MX Anywhere 3S Compact Wireless Mouse, Fast Scrolling, 8K DPI Any-Surface Tracking, Quiet Clicks, Programmable Buttons, USB C, Bluetooth, Windows PC, Linux, Chrome, Mac - Graphite

Logitech MX Anywhere 3S Compact Wireless Mouse, Fast Scrolling, 8K DPI Any-Surface Tracking, Quiet Clicks, Programmable Buttons, USB C, Bluetooth, Windows PC, Linux, Chrome, Mac - Graphite

  • TRACKS ANYWHERE: WORKS ON ANY SURFACE, INCLUDING GLASS, WITH EASE.
  • QUIET CLICKS: ENJOY A SATISFYING FEEL WITH REDUCED NOISE FOR FOCUS.
  • MULTI-DEVICE CONNECTIVITY: CONNECT UP TO 3 DEVICES EFFORTLESSLY VIA BLUETOOTH.
BUY & SAVE
$79.99 $89.99
Save 11%
Logitech MX Anywhere 3S Compact Wireless Mouse, Fast Scrolling, 8K DPI Any-Surface Tracking, Quiet Clicks, Programmable Buttons, USB C, Bluetooth, Windows PC, Linux, Chrome, Mac - Graphite
8 RAPIQUE Wireless Bluetooth Mouse, Purple, 1600 DPI, Long Battery Life, Dual Connectivity, Quiet Click, High-Precision Optical Tracking, Versatile Compatibility

RAPIQUE Wireless Bluetooth Mouse, Purple, 1600 DPI, Long Battery Life, Dual Connectivity, Quiet Click, High-Precision Optical Tracking, Versatile Compatibility

  • ERGONOMIC DESIGN: SLIM, PORTABLE SHAPE FOR ULTIMATE COMFORT ON-THE-GO.

  • NOISE REDUCTION: ENJOY SILENT CLICKS-PERFECT FOR QUIET ENVIRONMENTS.

  • DUAL CONNECTIVITY: SEAMLESSLY SWITCH BETWEEN DEVICES WITH ONE CLICK.

BUY & SAVE
$16.99
RAPIQUE Wireless Bluetooth Mouse, Purple, 1600 DPI, Long Battery Life, Dual Connectivity, Quiet Click, High-Precision Optical Tracking, Versatile Compatibility
+
ONE MORE?

In tkinter, you can add a mouse click position to a list by binding the mouse click event to a function that captures the x and y coordinates of the click. You can use the bind method to bind the mouse click event to a function, and within that function, you can access the event object to get the x and y coordinates of the mouse click. You can then append these coordinates to a list or data structure of your choice. This allows you to keep track of the mouse click positions and use them for further processing or manipulation in your tkinter application.

How to add a mouse click position to a list in tkinter using Python?

To add a mouse click position to a list in Tkinter using Python, you can use the following steps:

  1. Create an empty list to store the mouse click positions. You can define this list at the beginning of your program or inside the function where you handle mouse clicks.
  2. Define a function that will be called when the mouse is clicked on a widget. This function should take the event object as a parameter, which contains information about the mouse click event.
  3. Inside the function, extract the x and y coordinates of the mouse click from the event object using event.x and event.y.
  4. Append the x and y coordinates to the list you created in step 1 using the append() method.

Here's an example code snippet that demonstrates how to add mouse click positions to a list in Tkinter using Python:

import tkinter as tk

Create an empty list to store mouse click positions

mouse_click_positions = []

def on_click(event): x = event.x y = event.y mouse_click_positions.append((x, y)) print(f"Mouse click position: ({x}, {y})")

Create the main window

root = tk.Tk() root.title("Mouse Click Positions")

Create a canvas widget to capture mouse clicks

canvas = tk.Canvas(root, width=400, height=400) canvas.pack()

Bind the mouse click event to the canvas widget

canvas.bind("", on_click)

Start the Tkinter main loop

root.mainloop()

In this example, we create a Tkinter window with a canvas widget that captures mouse clicks. When the user clicks on the canvas, the on_click function is called, which extracts the x and y coordinates of the mouse click and appends them to the mouse_click_positions list. You can then use this list for further processing or to store the mouse click positions for later use.

How to sort the list of mouse click positions in tkinter?

To sort a list of mouse click positions in Tkinter, you can use the sorted() function to sort the list based on the x or y coordinates of the mouse click positions.

Here's an example code snippet to demonstrate how to sort a list of mouse click positions based on the x coordinates:

import tkinter as tk

click_positions = []

def on_click(event): click_positions.append((event.x, event.y))

def sort_positions_by_x(): sorted_positions = sorted(click_positions, key=lambda x: x[0]) print("Sorted positions by x:", sorted_positions)

root = tk.Tk() canvas = tk.Canvas(root, width=200, height=200) canvas.pack() canvas.bind("", on_click)

sort_button = tk.Button(root, text="Sort positions by x", command=sort_positions_by_x) sort_button.pack()

root.mainloop()

In this code, the on_click function appends the x and y coordinates of the mouse click positions to the click_positions list. The sort_positions_by_x function sorts the list of positions by the x coordinates using the sorted() function with a lambda function as the key to sort based on the x coordinate.

You can modify this code to sort the positions based on the y coordinates or any other criteria by changing the key function in the sorted() function.

How can I keep track of multiple mouse click positions in tkinter?

One way to keep track of multiple mouse click positions in tkinter is to create a list or a dictionary to store the x and y coordinates of each mouse click event. You can then bind a mouse click event to a function that updates this list or dictionary with the current mouse click position.

Here is an example code snippet that demonstrates how to achieve this:

import tkinter as tk

class App: def __init__(self, root): self.root = root self.root.bind("", self.on_click) self.mouse_click_positions = []

def on\_click(self, event):
    self.mouse\_click\_positions.append((event.x, event.y))
    print("Mouse click position:", event.x, event.y)

if __name__ == "__main__": root = tk.Tk() app = App(root) root.mainloop()

In this code snippet, a list called mouse_click_positions is created in the __init__ method of the App class. The on_click method is bound to the <Button-1> event, which is the left mouse button click event in tkinter. When a mouse click event occurs, the x and y coordinates of the event are added to the mouse_click_positions list.

You can then access and use this list to keep track of multiple mouse click positions in your tkinter application.