0

So in my tkinter app I need to check input on button but when I start the program with this code it starts the function (without me clicking the button) and I have no idea why it does that is.

submit = tk.Button(app,text='Submit details',bg='black',fg='white',
                   command=threading.Thread(target=get_input_info).start()).grid(row=4)
martineau
  • 119,623
  • 25
  • 170
  • 301
BFG_KO
  • 3
  • 3
  • You are also assigning the value `None` to `submit` because that's what the `grid()` method *always* returns. – martineau Jul 14 '21 at 14:25
  • `tkinter` isn't meant to be called from different threads. So please only call `tkinter` functions from the thread where you created the `Tk()` – TheLizzard Jul 14 '21 at 15:44

2 Answers2

0

Just remove the pair of parantheis from the end of the command argument.

eg:

from tkinter import *
import threading


def hehe():
    print("some stuff")

win=Tk()
submit = Button(text="something", command=threading.Thread(target=hehe).start).pack()
win.mainloop()
MrHola21
  • 301
  • 2
  • 8
0

You need to remove Parenthesis -

command=threading.Thread(target=get_input_info).start

Or use, lambda (useful when you need to pass args) -

command=lambda:threading.Thread(target=get_input_info).start()
PCM
  • 2,881
  • 2
  • 8
  • 30