Just starting out with tkinter and was checking on button and this problem arose.
import tkinter as tk
def showtext(text):
txt = tk.Text(gui)
txt.insert(tk.END, text)
txt.pack()
gui = tk.Tk()
btn = tk.Button(gui, text="this is a button", fg="white", bg="black",
activebackground="red", activeforeground="purple", command=showtext("this worked"))
btn.place(x=280, y=230)
gui.title('GUI')
gui.geometry("700x500+50+50")
gui.mainloop()
Here the text is supposed to be shown when the button is clicked, but the function is executed before that and the text is shown when I run the code.