In this section, we will learn how to exit the program in Python Tkinter.
Python Tkinter Exit Program
To quit a program we need to destroy the window. There is a built-in method
() to close the window in Python Tkinter.
Here ws is the main window & is the variable for Tk() class method.
Here is the the small demonstration of Python Tkinter Exit Program.
In this code, we have created a simple button on the window. When the user will click on the button it will close the window.
from tkinter import * from tkinter import messagebox from time import * def close(): ws.destroy() ws = Tk() ws.title("PythonGuides") ws.geometry("400x300") ws['bg']='#5d8a82' Button( ws, text="EXIT PROGRAM", font=("Times", 14), command=close ).pack(pady=100) ws.mainloop()
In this output, Button with the text “Exit Program” is displayed. When user will click on this button the window will close.
You may like the following Python tutorials:
- Python Tkinter TreeView Example
- Python Tkinter ToDo List
- Python Tkinter Window Size
- Python Tkinter Canvas Tutorial
- Python Tkinter Progress bar
- Python Tkinter Stopwatch
- Python Tkinter Listbox
- How to go to next page in Python Tkinter Program
- How to Create Countdown Timer using Python Tkinter
So in this tutorial, we have learned how to exit the program in Python Tkinter or how to quit the program in python Tkinter.