Question

I am a beginner programmer. I would like to resize my button, which is defined as "but", and it's defined in the Square class. What option would I use to adjust the size of this button to adjust the height and width? Any help is greatly appreciated and if you could add comments in your code that would be helpful!

import Tkinter

class TicWindow(Tkinter.Tk):
    def __init__(self):
        Tkinter.Tk.__init__(self)
    self.squares = []
    self.turn = 0
    for r in range(3):
        for c in range(3):
            b = Square(self).grid(row=r,column=c)
            self.squares.append(b)
    self.geometry("500x500")

def turn(self):
    return self.turn

def changeTurn(self):
    if (self.turn == 0): 
        self.turn = 1
    else: 
        self.turn = 0

class Square(Tkinter.Button):
def __init__(self,parent):
    but = Tkinter.Button.__init__(self,parent, text=" ", command=self.changeButtonText)

    self.canClick = True

def changeButtonText(self):
    if (self.master.turn == 0) and (self.canClick == True):
        self.config(text = "X")
    elif (self.master.turn == 1) and (self.canClick == True):
        self.config(text = "O")
    self.master.changeTurn()
    self.hasBeenClicked()

def canClick(self):
    return self.canClick

def hasBeenClicked(self):
    self.canClick = False

class ScoreBoard(Tkinter.Tk):
def __init__(self):
    Tkinter.Tk.__init__(self)
    self.board = Tkinter.Label(self, text = "No Score Yet")
    self.board.pack()
    self.geometry("500x500+300+300")

top = TicWindow()
scoreboard = ScoreBoard()
top.mainloop()
Was it helpful?

Solution

This has a simple answer. Basically, just add the height and width variables when you create the buttons:

Tkinter.Button.__init__(self,parent, text=" ", command=self.changeButtonText, height = 20, width = 30)

You can modify the height and width buttons to change the size of the button.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top