Python Tkinter Button

In this tutorial we will learn about Python Tkinter Button. This Python Tkinter widget us used to add different kinds of buttons in our Python application. You can set configurations of button according to requirements of your application. Furthermore we can set functionality to our button that what will happen when this button will get pressed. In this tutorial we will see different Tkinter button options that how we can customize our Button.

Python Tkinter Button, Tkinter Button Options


Example Program of Tkinter Button in Python:

Without wasting time I would like to start with this example program that how we can add Python Tkinter Button in our application.

Example

from tkinter import *  

#setting up main window 
mainWindow = Tk()  
  
#setting size of main window 
mainWindow.geometry("200x100")  

#Creating new button  
myButton = Button(mainWindow,text = "Submit")  
  
myButton.pack()  

mainWindow.mainloop()     



Example Program of Tkinter Button click action in Python:

In this example program we will learn how we can perform some action when our button will get clicked.

Example

from tkinter import *  
from tkinter import messagebox

#setting up main window 
mainWindow = Tk()  
  
#setting size of main window 
mainWindow.geometry("200x100")  

# defining a function
def show():  
    messagebox.showinfo("Info", "Hello, You Clicked this Button")  

#Creating new button  
myButton = Button(mainWindow,command = show, text = "Submit")  
  
myButton.pack()  

mainWindow.mainloop()     



Various Possible Options in Python Tkinter Button:

Option Description
activebackground This option helps us to set background color of button on mouse hover.
activeforeground This option helps us to set font color of button on mouse hover.
Bd This option helps us to set border width in pixel.
Bg This option helps us to set background color button.
Fg This option helps us to set foreground color button.
Font This option helps us to set font of button.
Height This option helps us to set height of button.
Highlightcolor This option helps us to set Highlight color when button will get focus.
Image This option helps us to set image displayed on button.
Padx This option helps us to set horizontal padding in button.
Pady This option helps us to set vertical padding in button.
Relief This option helps us to set type of border on button like SUNKEN, RAISED, GROOVE, and RIDGE..
State This option helps us to set button disable.
Underline This option helps us to set button text underline.
Width This option helps us to set width of button.


Python Tkinter ButtonClick Here to Download Jupyter Notebook file of This Tutorial.


Share this tutorial with your friends on your social Media..

Python Tkinter Button Python Tkinter Button Python Tkinter Button Python Tkinter Button



Now You Can Follow All These Tutorials on Your Android Mobile Just Download This App.


Owlbuddy.com