Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (18.4k points)

I want my label/text to be the desired location but when I use a method grid(row=, column=), my text will always appear to be top left which is by default. What is a problem with my code? Here is the code:

class ticTacToeUI():

    master = 0

    player1 = 0

    player2 = 0

    def __init__(self):

        self.setUp()

        self.playerDisplay()

        #self.boardDisplay()

        #self.quitButton()

        self.runUI()

      

    def setUp(self):

        self.master = tk.Tk()

        self.master.title("Tic Tac Toe Game")

        self.master.geometry("800x600")

        self.master.configure(background="white")

        self.master.resizable(1,1)

    def playerDisplay(self):

        text = tk.Label(self.master, text="Player 1: O\nPlayer 2: X",bg="white",fg="black", font=(None,15))

        text.grid(row=400, column=500)``` 

1 Answer

0 votes
by (36.8k points)
edited by

You are getting this error because it only has one widget, try adding more widgets or text.place(x=400, y=500)

If you are a beginner and want to know more about Python the do check out the Data Science with Python Course

Browse Categories

...