Reputation: 51
I'm making a tic-tac-toe game in python and right now I'm designing the GUI using Tkinter. The problem is that when I add 3 X's or O's to a row, the height of the button shrinks. I've played around with (i)padx and (i)pady and changing the font size, but nothing I've done has solved the issue. Anyone know how to fix this?
from tkinter import *
win = Tk()
win.configure(bg='light blue')
win.geometry('430x560')
win.title('TicTacToe')
win.resizable(False, False)
lblTitle = Label(win, text='Tic-Tac-Toe', font="Verdana 25 bold", fg='thistle4', bg='azure2',
highlightthickness=2, highlightbackground='thistle3')
lblTitle.pack(ipadx=20, ipady=5, padx=50, pady=10)
p1_turn = False
def click(ind):
if p1_turn:
btnTTT[ind].config(text="X", font='Verdana 45 bold')
else:
btnTTT[ind].config(text="O", font='Verdana 45 bold')
tttFrame = Frame(win, bg='azure2', highlightthickness=2, highlightbackground='thistle3')
tttFrame.pack()
btnTTT = list()
i = 0
for row in range(3):
for col in range(3):
btnTTT.append(Button(tttFrame, text="", bg='cadet blue', height=1, width=1,
fg='thistle', font="Verdana 50", relief='groove',
command=lambda c=i: click(c)))
btnTTT[i].grid(row=row, column=col, sticky="nesw", padx=15, pady=10, ipadx=15, ipady=15)
i = i + 1
mainFrame = Frame(win, bg='azure2', highlightthickness=2, highlightbackground='thistle3')
mainFrame.pack(pady=10)
scoreFrame = Frame(mainFrame, bg='azure2')
scoreFrame.grid(row=0, column=0, pady=10)
scoreboard = LabelFrame(scoreFrame, bg='azure2', fg='thistle4', text='Score', font='Verdana 15 bold', labelanchor='nw')
scoreboard.pack(padx=15)
lblPX = Label(scoreboard, bg='thistle', text="Player X:")
lblPX.grid(row=0, column=0, pady=5, padx=5)
lblPO = Label(scoreboard, bg='thistle', text="Player O:")
lblPO.grid(row=1, column=0, pady=5, padx=5)
lblPXScore = Label(scoreboard, bg='white', text=' ', relief='sunken')
lblPXScore.grid(row=0, column=1, padx=5)
lblPOScore = Label(scoreboard, bg='white', text=' ', relief='sunken')
lblPOScore.grid(row=1, column=1, padx=5)
butFrame = Frame(mainFrame, bg='azure2')
butFrame.grid(row=0, column=1)
btnReset = Button(butFrame, text="Reset", font='Verdana 15', fg='thistle')
btnReset.grid(row=0, column=0, padx=15, pady=5, ipady=4, ipadx=3)
btnExit = Button(butFrame, text='Exit', font='Verdana 15', fg='thistle')
btnExit.grid(row=1, column=0, padx=15, pady=5, ipady=3, ipadx=9)
win.mainloop()
Upvotes: 1
Views: 215
Reputation: 71
It appears that you are having a format problem where the text change is directly changing the size of your button...
Verdana 45 bold
needs to match
Verdana 50"
Notice how one is size 50 and not bold, while the other is 45 and bold? If you change the top line to Verdana 50 and remove "bold" this will directly fix your issue.
For me the issues were on line 18, 19 that need to match line 32.
Upvotes: 1