Button Widget Example 1 in Tkinter

 


import tkinter as tk


# Create the main application window

root = tk.Tk()

root.title("Button Attributes Example")


# Define a function to be called when the button is clicked

def button_clicked():

    print("Button clicked!")


# Create a button widget with various attributes

button = tk.Button(root, text="Click Me!",  # Text displayed on the button

                   width=10,               # Width of the button

                   height=2,               # Height of the button

                   bg="blue",              # Background color of the button

                   fg="white",             # Text color of the button

                   font=("Arial", 12),     # Font of the text on the button

                   command=button_clicked) # Function to call when the button is clicked


# Place the button widget in the main window

button.pack()


# Run the Tkinter event loop

root.mainloop()







Comments