Your buttonPushed
function is unnecessary because you can assign the button's command
parameter to the root.destroy
function directly:
button = tk.Button(root, text="exit", command=root.destroy)
Thus, your code becomes just this1:
import Tkinter as tk
def main():
root = tk.Tk()
message = tk.Label(root, text="Hello World")
message.pack()
button = tk.Button(root, text="exit", command=root.destroy)
button.pack()
tk.mainloop()
main()
1Note: I also removed the global root
line at the top of main
because it is unnecessary.