Welcome folks today in this blog post we will be showing popup messagebox dialog box using msgbox.showinfo() method on button click
in tkinter
gui desktop app in python. All the full source code of the application is given below.
Get Started
In order to get started you need to install the below library using the pip
command as shown below
pip install tkinter
After installing this library you need to make an app.py
file and copy paste the following code
app.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
import tkinter as tk import tkinter.messagebox as msgbox class Window(tk.Tk): def __init__(self): super().__init__() self.title("Hello Tkinter") self.label_text = tk.StringVar() self.label_text.set("Choose One") self.label = tk.Label(self, textvar=self.label_text) self.label.pack(fill=tk.BOTH, expand=1, padx=100, pady=30) hello_button = tk.Button(self, text="Say Hello", command=self.say_hello) hello_button.pack(side=tk.LEFT, padx=(20, 0), pady=(0, 20)) goodbye_button = tk.Button(self, text="Say Goodbye", command=self.say_goodbye) goodbye_button.pack(side=tk.RIGHT, padx=(0, 20), pady=(0, 20)) def say_hello(self): msgbox.showinfo("Hello", "Hello World!") def say_goodbye(self): self.label_text.set("Window will close in 2 seconds") msgbox.showinfo("Goodbye!", "Goodbye, it's been fun!") self.after(2000, self.destroy) if __name__ == "__main__": window = Window() window.mainloop() |
If you execute the above python script
by typing the below command
python app.py