Posts

Showing posts with the label coordinates

How to get the clicks coordinates python 3

How to get the clicks coordinates python 3 I am making a cross-zero game on python 3.5.4 with tkinter. I have made this at the moment: from sys import * from tkinter import * screen = Tk() c = Canvas(width=600, height=600) c.pack() Line1 = c.create_line(200, 0, 200, 600) Line2 = c.create_line(400, 0, 400, 600) Line3 = c.create_line(0, 200, 600, 200) Line4 = c.create_line(0, 400, 600, 400) Then, I want to make to make the main loop. And I think that it'll be better if I make it with using clicks' coordinates. But how can I get them? Or maybe I should make the game with using buttons? 1 Answer 1 Here is one way to access the canvas coordinates of a mouse click: import tkinter as tk def click(event): print(event.x, event.y) if __name__ == '__main__': screen = tk.Tk() canvas = tk.Canvas(width=600, height=600) canvas.pack() canvas.bind('<Button-1>', click...

(check if) Mouse in cycle? (coordinate Js canvas)

(check if) Mouse in cycle? (coordinate Js canvas) So, I want to check, if the mouse is (clicked) inside of a ring. Here it (the ring) is : <canvas id="textur" width="1584" height="750"></canvas> <script> var textur = document.getElementById('textur'); var canvas = textur.getContext('2d');//Dimension zähler = 0; diff = ((1)*Math.PI*2*10).toFixed(2) canvas.lineWidth = 95 ; canvas.fillStyle = '#09F' canvas.strokeStyle = '#09F' canvas.textAlign = 'center' canvas.beginPath(); canvas.arc(150, 100, 5, 4.72, diff / 10 + 4.72, false) canvas.stroke(); </script> So, I know how to do it with a rectangle,but with a ring... I´m happy about every (useful) answer! Possible duplicate of Detect if user clicks inside a circle – AndroidNoobie Jul 1 at 9:08 ...