Tkinter is Python’s standard GUI (Graphical User Interface) package. It is one of the most commonly used packages for GUI applications which comes with Python itself. Let’s see how to create a button using Tkinter.
Follow the below steps:
- Import tkinter module # Tkinter in Python 2.x. (Note Capital T)
- Create main window (root = Tk())
- Add as many widgets as you want.
Importing tkinter module is same as importing any other module.
import tkinter # In Python 3.x
import Tkinter # In python 2.x. (Note Capital T)
The tkinter.ttk module provides access to the Tk-themed widget set, introduced in Tk 8.5. If Python has not been compiled against Tk 8.5, this module can still be accessed if Tile has been installed. The former method using Tk 8.5 provides additional benefits including anti-aliased font rendering under X11 and window transparency.
The basic idea for tkinter.ttk is to separate, to the extent possible, the code implementing a widget’s behavior from the code implementing its appearance. tkinter.ttk is used to create modern GUI (Graphical User Interface) applications that cannot be achieved by tkinter itself.
Code #1: Creating button using Tkinter.
Python3
from tkinter import *
root = Tk()
root.geometry( '100x100' )
btn = Button(root, text = 'Click me !' , bd = '5' ,
command = root.destroy)
btn.pack(side = 'top' )
root.mainloop()
|
Output:

Creation of Button without using tk themed widget.
Creation of Button using tk themed widget (tkinter.ttk). This will give you the effects of modern graphics. Effects will change from one OS to another because it is basically for the appearance.
Code #2:
Python3
from tkinter import *
from tkinter.ttk import *
root = Tk()
root.geometry( '100x100' )
btn = Button(root, text = 'Click me !' ,
command = root.destroy)
btn.pack(side = 'top' )
root.mainloop()
|
Output:

Note: See in the Output of both the code, BORDER is not present in 2nd output because tkinter.ttk does not support border. Also, when you hover the mouse over both the buttons ttk.Button will change its color and become light blue (effects may change from one OS to another) because it supports modern graphics while in the case of a simple Button it won’t change color as it does not support modern graphics.
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
16 Feb, 2021
Like Article
Save Article