Python Button Widget
Python Button Widget
Let’s learn about the Python Button Widget in this tutorial. The button widget is a Tkinter widget that is used to create a button on the GUI. A button allows the user to perform an action when the mouse is clicked on the button.
Syntax
The general syntax to create a button widget is as follows:
w= Button (window, option =value,….)
Parameters
- window: This represents the parent window.
- options: Here is the list of most commonly used options for this widget. These options can be used as key-value pairs separated by commas.
Example
# Python Program – Button Widget
# Python Tutorials – www.TestingDocs.com
from tkinter import *
import tkinter.messagebox
def click():
tkinter.messagebox.showinfo(“TestingDocs.com”,”Button Clicked”)
# Create the window
window = Tk()
window.geometry(‘800×400’)
window.title(“Python Button Demo”)
button = Button(window, text=”Python Tutorials”, command=click)
button.pack()
# Start the Tkinter event loop
window.mainloop()
—
Python Tutorials
Python Tutorial on this website can be found at:
https://www.testingdocs.com/python-tutorials/
More information on Python is available at the official website: