0

Button Command in tkinter PYTHON

I successed to make tic-tac-toe in python so I tried making tic-tac-toe in tkinter. Then I made nine buttons and tried using command to them. But there were some errors. So I started to test parameter, ‘command’. The codes were like this(test): —————————————————————— from tkinter import * def click(): btn.configure(text = ‘O’) window = Tk() btn = Button(window, command = click) window.mainloop() —————————————————————— It worked well;; But this codes got errors: —————————————————————— from tkinter import * def click(a): if a == 1: btn.configure(text = ‘O’) elif a == 2: btn.configure(text = ‘X’) window = Tk() btn = Button(window, command = click(1)) window.mainloop() —————————————————————— So, why are there some errors? Please let me know the reason.

7th Jun 2019, 11:29 AM
thexplore
thexplore - avatar
2 Answers
+ 4
use "lambda: click(1)"
7th Jun 2019, 12:38 PM
Mert Yazıcı
Mert Yazıcı - avatar
+ 2
click(1) is not a function, it is what click return with 1 as its parameter If you want to know which turn it is, you will have to store a as a global variable for example
7th Jun 2019, 11:39 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar