user1768884
user1768884

Reputation: 1047

set the coordinates of a tkinter window

How would I set up the coordinates of a tkinter window (size 500x500) so that the (0,0) point is at the bottom left, and the (500x500) is at the right top? Google hasn't been much help.

def graphDisplay(distance, elevation):
    '''draws up the graph.'''

    #creates a window
    root = Tk()

    #sets the name of the window
    root.title("Graph")

    #sets the size of the window
    root.geometry("500x500")

    #sets the background of the window
    root.configure(background='green')

    #create a canvas object to draw the circle
    canvas = Canvas(root)

    #runs the program until you click x
    root.mainloop

Upvotes: 1

Views: 1280

Answers (1)

Peter Varo
Peter Varo

Reputation: 12180

AFAIK you can't change that, but it is pretty easy, to calculate what you are looking for.

First of all, we have to notice, that x coordinate is the same even if the 0,0 is at the bottom-left or at the top-left corners of the canvas — so we don't have to do anything with that.

But y will change and it will depend on the width of canvas. So first, we have to store the width, and use it, to get the translated y value.

width = 500
root.geometry('500x{}'.format(width))

Now we can calculate with this width, so let's say, you want to add a point at 20,12 and the canvas is 500,500, then x won't change, and we have to translate y:

translated_y = width - 12  # which will be: 500 - 12 = 488

Upvotes: 1

Related Questions