Skip to content
Related Articles

Related Articles

Change color of button in Python – Tkinter
  • Last Updated : 23 Dec, 2020

Prerequisite: Creating a button in tkinter, Python GUI – tkinter

In this article, we are going to write a Python script to change the color of the button in Tkinter. It can be done with two methods:

  • Using bg properties.
  • Using activebackground properties.

Example 1: using bg properties.

We can change the button background color with bg properties, The default color of the button is grey but here we are going to change.

Python3



filter_none

edit
close

play_arrow

link
brightness_4
code

# import tkinter module 
from tkinter import *   
  
# create a tkinter window
master = Tk()  
  
# Open window having dimension 200x100
master.geometry('200x100')  
    
# Create a Button
button = Button(master, 
                text = 'Submit'
                bg='blue').pack()  
  
master.mainloop()

chevron_right


Output:

Example 2: Using activebackground properties.

These properties will change the button background color while clicking the button.

Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# import tkinter module 
from tkinter import *   
  
# create a tkinter window
master = Tk()  
  
# Open window having dimension 200x100
master.geometry('200x100')  
    
# Create a Button
button = Button(master, 
                text = 'Submit'
                bg='white'
                activebackground='blue').pack()  
    
master.mainloop()

chevron_right


Output:


Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :