I am making a Tic Tac Toe game in Python Tkinter but the buttons are rectangles, and I want them to all be 100x100 pixels in size. I tried using:
a1 = Button(root, text="", font="Helvetica 16 bold", command=a1, height=10, width=10)
(ignore the empty string and a1
) and yet it does not resize it into a square. I have written most of the code and don't want to use frames to resize them. What should I do?
One simple method is to give the button an invisible 1x1 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")
...