Tkinter

Button Tkinter | Python 3

In this tutorial, we are going to see how to use Button widget in Tkinter. The Button widget is used to add buttons to a Python application. These buttons can display text or images that translate their function. You can attach a function or a method to a button that is called automatically when you click on the button.
 


 
 

Syntax:

Here is the syntax to create this widget:

btn = Button ( master, option = value, ... )

 

Parameters:
  • master : This represents the parent window.
  • options : Options can be used as comma separated key-value pairs. See the following example:

 

 

Example:
import tkinter
from tkinter import messagebox

gui = tkinter.Tk()

def msgCallBack():
   messagebox.showinfo("StackHowTo", "Welcome to StackHowTo!")

btn = tkinter.Button(gui, text ="Click here!", command = msgCallBack)

btn.pack()
gui.mainloop()

Output:


 
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *