callback() missing 1 required positional argument: 'event' : <p>I am trying to create a Tkinter-GUI for selection of data points for analysis. This GUI will be part of a bigger Python routine that reduces the data.</p>

<p>The data points are numbered sequentially (#1, #2, #3, ...) and there is one checkbutton for each data point. When one button is clicked on, the corresponding data point number should be added to a list, like so [1, 3, 7]. The code I have written is as follows,</p>

<pre><code>"""
GRAPHICAL SELECTION OF DATA POINTS FOR ANALYSIS

""" 
# create an empty list of data points
selection = []

# import libraries and modules
from tkinter import *

# create parent window
parent = Tk()
parent.title('SELECT DATA POINTS FOR ANALYSIS')


# create callback functions
def callback1(event):
    selection.append(1) 

def callback2(event):
    selection.append(2)

def callback3(event):
    selection.append(3) 

def callback4(event):
    selection.append(4)

def callback5(event):
    selection.append(5)


# create list call
Label(parent,
      text="Check data points to be analyzed:",
      font=('arial', 12, 'bold')).grid(row=1,column=0,columnspan=11,sticky='w')

# create checkbuttons
button1 = Checkbutton(parent,text='#1',command=callback1) # create widget
button1.grid(row =2,column=0,columnspan=4,sticky='w') # position widget
button1.bind("&lt;Button-1&gt;",callback) # bind widget to left mouse click

button2 = Checkbutton(parent,text='#2',command=callback2)
button2.grid(row =3,column=0,columnspan=4,sticky='w')
button2.bind("&lt;Button-1&gt;",callback)

button3 = Checkbutton(parent,text='#3',command=callback3)
button3.grid(row =4,column=0,columnspan=4,sticky='w')
button3.bind("&lt;Button-1&gt;",callback)

button4 = Checkbutton(parent,text='#4',command=callback4)
button4.grid(row =5,column=0,columnspan=4,sticky='w')
button4.bind("&lt;Button-1&gt;",callback)

button5 = Checkbutton(parent,text='#5',command=callback5)
button5.grid(row =6,column=0,columnspan=4,sticky='w')
button5.bind("&lt;Button-1&gt;",callback)


parent.mainloop()

print("selection =",selection)
</code></pre>

<p>I have created the checkbuttons and bound them to the corresponding callback function. Apparently, the event (left button mouse click) is also correctly specified, i.e. "". </p>

<p>When I run this code, the GUI is properly created and shown. However, upon clicking on any button I get the following error message:</p>

<pre><code>Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\ridim\Anaconda3\lib\tkinter\__init__.py", line 1558, in __call__
    return self.func(*args)
TypeError: callback1() missing 1 required positional argument: 'event'
</code></pre>

<p>I am relatively new to Tkinter and I could not figure out what I am doing wrong. The syntax callback is apparently correct and the word "event" appears in the function definitions.</p>

<p>I would be very grateful if someone could tell me what is wrong with my code. In addition, I would like to ask whether there is a more efficient way of setting up the callback functions. Maybe, a single callback function with "if" statements.</p>

<p>Many thanks,</p>

<p>Carvalho</p>
