from tkinter import ttk import tkinter as tk root = tk.Tk() button = ttk.Button(root, text="Click me!") button.pack() root.mainloop()
from tkinter import ttk import tkinter as tk def button_clicked(): print("Button clicked!") root = tk.Tk() button = ttk.Button(root, text="Click me!", command=button_clicked) button.pack() root.mainloop()This code creates a button with the text "Click me!" and attaches a command to it. When the button is clicked, the button_clicked() function is called and the message "Button clicked!" is printed to the console. These examples demonstrate how to use the tkinter.ttk Button pack to create and customize buttons in a user interface. The package library is the standard Python GUI library tkinter.