buttons tkinter api code example
Example 1: how to make a button in python
import tkinter as tk
def write_slogan():
print("Tkinter is easy to use!")
root = tk.Tk()
frame = tk.Frame(root)
frame.pack()
button = tk.Button(frame,
text="QUIT",
fg="red",
command=quit)
button.pack(side=tk.LEFT)
slogan = tk.Button(frame,
text="Hello",
command=write_slogan)
slogan.pack(side=tk.LEFT)
root.mainloop()
Example 2: add a button on tkinter
import tkinter
button1 = ttk.Button(self, text="anything", command=random command)
button1.pack()