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): if msgbox.askyesno("Close Window?", "Would you like to close this window?"): self.label_text.set("Window will close in 2 seconds") self.after(2000, self.destroy) else: msgbox.showinfo("Not Closing", "Great! This window will stay open.") if __name__ == "__main__": window = Window() window.mainloop()