Getting position of user click in pygame
<p>I have a pygame window embedded in a a frame in tkinter. In another frame I have a button which calls the following function when clicked:</p>

<pre><code>def setStart():
global start
# set start position
for event in pygame.event.get():
    if event.type == pygame.MOUSEBUTTONUP:
        start = event.pos
        print("start",start)
        break
</code></pre>

<p>I am intending for the program to print the position of the place where the user clicked on the pygame surface after the button is clicked. However on the first click of the button and the following click of the pygame surface there is no output. It is on the second click of the button <em>before the corresponding second  click on the pygame surface</em> that python prints out an output like : </p>

<p>('start', (166, 115))</p>

<p>How can I get it to give me a result right after the click on the pygame surface? I had the same problem when I had two seperate tkinter and pygame windows so the embedding of pygame into tkinter is unlikely to be the cause of the problem.</p>

<p>EDIT: after further testing it appears that if the button is pressed and then the pygame surface is clicked on multiple times, upon a second click of the button the coordinates of all of these clicks are printed out as a batch. </p>

<p>First I have to say that I don't know anything about pygame. However, if you are already using Tkinter, I could help you maybe: I would define a new function (let's call it mouse_click). In the button-click-function I would bind the new function to the game's surface. In the new function I print out the current mouse position:</p>

<pre><code>def button_click(self):
    game_surface.bind("&lt;Button-1&gt;", self.mouse_click)

def mouse_click(self, event):
    print "X:", event.x
    print "Y:", event.y
</code></pre>

<p>I hope this is helpful. Please notice that you should modify this code to make it work in your program (using the correct widget names and so on).
By the way, "Button-1" is the event identifier of the left mouse button.</p>

python python-2.7 tkinter pygame pygame-surface