0

I'm making a Tkinter GUI, and I want a button in it and if you click it there is a label under it and it will display how many times you've clicked. But it tells me there is a Syntax Error but I don't seem to find it.

I've tried to change the " to ' and so on but nothing works!!

def KlickCounter():
    Klicks = Klicks + 1
    Counter.configure(text='You have clicked the button ' + Klicks ' times')

I expect the Label to display the number "Klicks" which is the number of how many times you've clicked the button.

petezurich
  • 9,280
  • 9
  • 43
  • 57

2 Answers2

2

You are simply missing another + after Klicks in your Counter.configure call :)

OsmosisJonesLoL
  • 244
  • 1
  • 4
0

As @OsmosisJonesLoL mentioned in his answer, simply replace

Counter.configure(text='You have clicked the button ' + Klicks ' times')

with

Counter.configure(text='You have clicked the button ' + Klicks + ' times')

By adding + right after Kicks.

However, I wanted to suggest: Avoid using + in order to concatenate strings. You can do it much better like this:

Counter.configure(text='You have clicked the button {} times'.format(Klicks))

Or, even better, if you have python 3.6 or above, you can do it like this:

Counter.configure(text=f'You have clicked the button {Klicks} times')
Amir Shabani
  • 3,857
  • 6
  • 30
  • 67