hashdankhog
hashdankhog

Reputation: 25

Unable to use place()

I'm trying to use tkinter and am needing to have a object go to certain coordinates and I've tried place but it gives me an error:

player.place(x=0, y=0)
AttributeError: 'int' object has no attribute 'place'

and also all tutorials for the place command only cover the use for buttons. So I'm wondering if it's exclusive to Buttons.

from tkinter import *
import time

tk = Tk()

canvas = Canvas(tk, width=400, height=400)
canvas.pack()
player = canvas.create_rectangle(10, 10, 50, 50)

player.place(x=0, y=0)

Upvotes: 0

Views: 57

Answers (2)

mlacix
mlacix

Reputation: 1

If you want to move only the rectangle and not the canvas, you could try something like this:

canvas.coords(player,x0,y0,x1,y1) 

as

canvas.coords(player,10,20,50,60)

Upvotes: 0

Bryan Oakley
Bryan Oakley

Reputation: 385900

place can only be used on widgets. Canvas items aren't widgets. Plus, there's no point in using place on canvas objects since part of the definition or the canvas object requires the coordinates where the object will be added to the canvas.

Upvotes: 1

Related Questions