-2

My message box launches automatically without me clicking the button first when I run it in Pycharm.

from tkinter import *
from PIL import ImageTk,Image
from tkinter import messagebox

root = Tk()
root.title('Frame')
root.iconbitmap('D:\Tkinter\Frame.ico')


def popup():
    messagebox.showinfo("Popup","You have clicked a button!")

Button(root, text = 'Click Me!',commmand=popup()).pack()

root.mainloop()

And this is what I get when I run it

Nuked22
  • 3
  • 1
  • Read [Why is parameter “command=” executed when declared?](https://stackoverflow.com/questions/5767228/why-is-button-parameter-command-executed-when-declared) – stovfl Mar 22 '20 at 12:09

1 Answers1

0

In Button declaration, you are calling your function instead of passing a callback to it.

There is also a typo in a word 'command' - you wrote it with 3x m.

So, you should declare your button as:

Button(root, text = 'Click Me!',command=popup).pack()

How to create a basic button