How do I resize buttons in pixels? (Tkinter)

One simple method is to give the button an invisible 1×1 pixel image. When you do that, the width and height attributes are interpreted as pixels (or more accurately, screen units, which could also mean points, inches, or centimeters).

If you do this, you can set compound to the value “c” to mean that the button should show both text and the image, with both being centered on the window.

For example:

import Tkinter as tk
...
pixel = tk.PhotoImage(width=1, height=1)
button = tk.Button(root, text="", image=pixel, width=100, height=100, compound="c")
...

Leave a Comment