Tkinter is Python’s standard GUI (Graphical User Interface) package. It is one of the most commonly used package for GUI applications which comes with the Python itself. Let’s see how to create a button using Tkinter.
Follow 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 which cannot be achieved by tkinter itself.
Code #1: Creating button using Tkinter.
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.
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 mouse over both the buttons
ttk.Button will change it’s color and become light blue (effects may change from one OS to another) because it supports modern graphics while in case of simple Button it won’t change color as it does not support modern graphics.
- Python | Add style to tkinter button
- Python | Add image on a Tkinter button
- Python GUI - tkinter
- Python | after method in Tkinter
- RadioButton in Tkinter | Python
- Different messages in Tkinter | Python
- Python: Age Calculator using Tkinter
- maxsize() method in Tkinter | Python
- Python | pack() method in Tkinter
- Python | Create a GUI Marksheet using Tkinter
- Python | askopenfile() function in Tkinter
- Python | geometry method in Tkinter
- Python | Binding function in Tkinter
- iconphoto() method in Tkinter | Python
- Combobox Widget in tkinter | Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.