Introduction
In this article, I will explain how to add buttons in the tkinter in Python.
Definition
The Button keyword is used to add buttons in a Python application. The buttons can display text or photos that convey the cause of the buttons. You can attach a function to a button. When you click the button, it will go to the function.
Syntax
- b = Button (a, option)
Parameters
a − This represents the parent window of the computer.
option − The list of most used options for this widget.
Option & Description
- active background - The active background is used to change Background color when the button is under the cursor.
- active foreground - The active foreground is used to change Foreground color when the button is under the cursor.
- bd - The bd is used to change the Border width in pixels. Default is 2.
- bg - The bg is used to change Normal background color background.
- command - The command is used to call a function or method when the button is clicked
program
- from tkinter import *
- import tkinter.messagebox
- a= Tk()
- def hello():
- tkinter.messagebox.showinfo( "Hello c#corner")
- b =Button(a, text ="Hello",activebackground="black" , activeforeground="white",bg="green",bd=10,command = hello)
- b.pack()
- a.mainloop()
Output

- fg - The fg is used to change the normal foreground (text) color.
- font - The font is used to change the text font to be used for the button's label.
- height - The height is used to change the height of the button in text lines (ftext buttons) or pixels (images).
- highlight color - The highlight color is used to change the color of the focus highlight when the widget has focus.
- image - Image keyword is used to be displayed on the button.



Join the conversation! Your thoughts help the community grow.