Problem regarding messagebox module in Tkinter

65 Views Asked by At

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

1

There are 1 best solutions below

3
On

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