Question

I am a beginner programmer! My program is not stellar. I just need to figure out how to resize the two windows I am calling on: TicWindow and ScoreBoard. Underneath my ScoreBoard class I have programmed self.board = TicWindow() & self.board.geometry("500x500+300+300"). I have read that to resize a window you need to call upon a root window, which is my TicWindow. I know that it is wrong because it looks like it is in the wrong place and it opens a third window that is resized. Any help is appreciated!

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)

    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):
        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").pack()

        self.board = TicWindow()
        self.board.geometry("500x500+300+300")

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

Solution

Sounds like you want to resize your ScoreBoard.

Inside ScoreBoard.__init__, there's no need to create another TicWindow instance. That's why you're getting three windows. Additionally, you shouldn't try to assign a widget and pack it on the same line - the variable will only contain None that way.

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")

Result:

enter image description here

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