Skip to main content

Create Button in Tkinter

 




from tkinter import *
root = Tk()
root.geometry("500x300")

f = Frame(root,borderwidth=6,bg="black",relief=SUNKEN)
f.pack(pady=90)


def bu1():
    print("Button b1")

def bu2():
    print("Button b2")

def bu3():
    print("Button b3")

def bu4():
    print("Button b4")

def bu5():
    print("Button b5")

def bu6():
    print("Button b6")

def button():
    b =  Button(f,fg="black",text="Click",bg="red",padx=10,pady=10,command=bu1).pack(side=LEFT)
    b2 = Button(f,fg="black",text="Click",bg="green",padx=10,pady=10,command=bu2).pack(side=LEFT)
    b3 = Button(f,fg="black",text="Click",bg="white",padx=10,pady=10,command=bu3).pack(side=LEFT)
    b4 = Button(f,fg="black",text="Click",bg="yellow",padx=10,pady=10,command=bu4).pack(side=LEFT)
    b5 = Button(f,fg="black",text="Click",bg="orange",padx=10,pady=10,command=bu5).pack(side=LEFT)
    b6 = Button(f,fg="black",text="Click",bg="blue",padx=10,pady=10,command=bu6).pack(side=LEFT)

button()
root.mainloop()




Comments