---
title: Creating a button in Tkinter
description: Creating a button in Tkinter
---

[Skip to content](https://www.connysoderholm.com/blog/creating-a-button-in-tkinter#main-content)

![Conny-Söderholm](https://www.connysoderholm.com/hubfs/Conny-S%C3%B6derholm.svg)

- [Home](https://www.connysoderholm.com/)
- [Courses](https://www.connysoderholm.com/courses)
- [Articles](https://www.connysoderholm.com/blog)
- [Contact Me](https://www.connysoderholm.com/contact-me)

Open main navigation

Close main navigation

- [Home](https://www.connysoderholm.com/)
- [Courses](https://www.connysoderholm.com/courses)
- [Articles](https://www.connysoderholm.com/blog)
- [Contact Me](https://www.connysoderholm.com/contact-me)

 July 9, 2018

# Creating a button in Tkinter

![Picture of Conny Söderholm](https://app.hubspot.com/settings/avatar/c60eb763b898c1f4c2e54f9401f3aef1) [Conny Söderholm](https://www.connysoderholm.com/blog/author/conny-soderholm)

Share: [facebook-f icon](http://www.facebook.com/share.php?u=https://www.connysoderholm.com/blog/creating-a-button-in-tkinter) [linkedin-in icon](http://www.linkedin.com/shareArticle?mini=true&url=https://www.connysoderholm.com/blog/creating-a-button-in-tkinter) [Twitter icon](https://twitter.com/intent/tweet?url=https://www.connysoderholm.com/blog/creating-a-button-in-tkinter) [pinterest-p icon](http://pinterest.com/pin/create/link/?url=https://www.connysoderholm.com/blog/creating-a-button-in-tkinter) [envelope icon](mailto:?body=https://www.connysoderholm.com/blog/creating-a-button-in-tkinter)

# Creating a button in Tkinter

In this article, we will explore how to create a simple button in Tkinter. The button is used for a lot of user interaction and is often the most basic way to interact with a user. We will also cover some basics of how a Tkinter application is launched.

## Setting up

After importing Tkinter we first create an application class from tk.Tk.  The super method inherits from the Tk class's init method. Note that we also passed an argument in the init method named button\_text. The label of the button will have this text on it.

## Creating the button

The init method also puts the button on the frame. Notice that the button will not be visible until we pack it or place it on the frame. The tk.Button creates the button. It accepts input such as text which defines what text the button should have. You can also create the button disabled by passing in the variable state="disabled" (use lower letter characters).  You can enable the button with "active". The button can also be created in distinct reliefs. The reliefs are tk.GROOVE, tk.FLAT, tk.RIDGE. The normal state is TK.RAISED. When you push the button is shown in the state tk.SUNKEN.

## Button up!

You can also pass an image to the button. Just create a button with tk.PhotoImage as below:

```
self.button_button_image = tk.PhotoImage(file="your_button_picture.png")
```

Then pass it with the variable image:

```
tk.Button(self, image = self.button_button_image, command=self.print_txt)
```

# Finishing up

What we do next is creating a method for the button, which we call when we press the button. Next, we create a root frame and pass the text "My button" to label our button. We run the application with the mainloop method.

```
#! python3

# -*- coding: utf-8 -*-

import tkinter as tk

class button_tester_app(tk.Tk):
def __init__(self, button_text):
super().__init__()
self._button_text = button_text
# Create the button
self.test_button = tk.Button(self, text = button_text, command=self.print_text)
# Put the button to the frame
self.test_button.pack()

def print_text(self):
# Print the text to the console
print("You pressed the \"{}\" test button!".format(self._button_text))

if __name__ == "__main__":
root = button_tester_app("My button")
root.mainloop()
```

 

[Python](https://www.connysoderholm.com/blog/tag/python)

## Related posts

[Python](https://www.connysoderholm.com/blog/tag/python)

## [Tkinter: Changing tk.Button text with Stringvar() and trace\_add](https://www.connysoderholm.com/blog/tkinter-button-text-stringvar)

![Picture of Conny Söderholm](https://app.hubspot.com/settings/avatar/c60eb763b898c1f4c2e54f9401f3aef1) [Conny Söderholm](https://www.connysoderholm.com/blog/author/conny-soderholm) 

 July 10, 2018

Tkinter: Changing tk.Button text with Stringvar() and trace\_add In this example, we will see how we...

[Read more](https://www.connysoderholm.com/blog/tkinter-button-text-stringvar)

[Python](https://www.connysoderholm.com/blog/tag/python), [pypdf2](https://www.connysoderholm.com/blog/tag/pypdf2)

## [Rotate PDF files with PyPdf2 and Tkinter!](https://www.connysoderholm.com/blog/rotate-pdf-files-with-pypdf2-and-tkinter)

![Picture of Conny Söderholm](https://app.hubspot.com/settings/avatar/c60eb763b898c1f4c2e54f9401f3aef1) [Conny Söderholm](https://www.connysoderholm.com/blog/author/conny-soderholm) 

 January 24, 2020

Rotating PDF files with PyPDF2 and Tkinter Introduction Sometimes we need simple tools to get the...

[Read more](https://www.connysoderholm.com/blog/rotate-pdf-files-with-pypdf2-and-tkinter)

[Python](https://www.connysoderholm.com/blog/tag/python)

## [Creating a simple file dialog box with Tkinter](https://www.connysoderholm.com/blog/file-dialog-box-tkinter)

![Picture of Conny Söderholm](https://app.hubspot.com/settings/avatar/c60eb763b898c1f4c2e54f9401f3aef1) [Conny Söderholm](https://www.connysoderholm.com/blog/author/conny-soderholm) 

 June 14, 2018

Creating a simple file dialog box with Tkinter - Have you come to a point when you want to avoid...

[Read more](https://www.connysoderholm.com/blog/file-dialog-box-tkinter)

[linkedin-in icon](https://www.linkedin.com/in/connysoderholm) [Follow us on Facebook](https://www.youtube.com/@connysoderholm1473)

- [Home](https://www.connysoderholm.com)
- [Courses](https://www.connysoderholm.com/courses)
- [Articles](https://www.connysoderholm.com/blog)
- [Contact Me](https://www.connysoderholm.com/contact-me)
- [Privacy Policy](https://www.connysoderholm.com/privacy-policy)
- [Disclaimer](https://www.connysoderholm.com/disclaimer)

---

[![Conny Söderholm Logo](https://www.connysoderholm.com/hubfs/Conny-S%C3%B6derholm.svg "Conny Söderholm Logo")](http://Conny%20Söderholm)

Copyright © 2026 Conny Söderholm

```json
{
  "@context" : "https://schema.org",
  "@type" : "BlogPosting",
  "author" : {
    "@type" : "Person",
    "name" : "Conny Söderholm",
    "url" : "https://www.connysoderholm.com/blog/author/conny-soderholm"
  },
  "dateModified" : "2023-07-31T14:58:23.563Z",
  "datePublished" : "2018-07-09T16:53:36.000Z",
  "headline" : "Creating a button in Tkinter",
  "mainEntityOfPage" : {
    "@id" : "https://www.connysoderholm.com/blog/creating-a-button-in-tkinter",
    "@type" : "WebPage"
  },
  "publisher" : {
    "@type" : "Organization",
    "logo" : {
      "@type" : "ImageObject",
      "url" : "https://www.connysoderholm.com/hubfs/Conny-S%C3%B6derholm.svg"
    },
    "name" : "Conny Söderholm"
  }
}
```