Home C C++ Java Python Perl PHP SQL JavaScript Linux Selenium QT Online Test

Home » Python » Tkinter Examples » Button

Python Tkinter Button Examples

Example 1


from tkinter import *

root = Tk()

myButton = Button(root, text="Hey Click Me!")
myButton.pack()

root.mainloop()
how to create button in python using tkinter

Disabling Button


from tkinter import *

root = Tk()

myButton = Button(root, text="Hey Click me!", state=DISABLED)
myButton.pack()

root.mainloop()
how to create button in python using tkinter

Showing Buttons in a grid


from tkinter import *

root = Tk()

myButton1 = Button(root, text="Button 1")
myButton2 = Button(root, text="Button 2")
myButton1.grid(row=0, column=0)
myButton2.grid(row=0, column=1)

root.mainloop()

Setting Padding in Button


from tkinter import *

root = Tk()

myButton = Button(root, text="Hey Click Me!", padx=55, pady=55)
myButton.pack()

root.mainloop()
Adding padding to buttons in Python tkinter