简体   繁体   中英

Anchor's value looked reversed in tkinter, python3.7

When I used anchor in place() mythod in tkinter, the button's position seems reverse to what I set.

from tkinter import *

win = Tk()


frame = Frame(win, relief=RAISED, borderwidth=1, width=400, height=300)
frame.pack(fill=BOTH, ipadx=5, ipady=5, expand=1)

button1 = Button(frame, text="Button 1")
button1.place(x=200, y=150, anchor=NW, width=200, height=150)


win.mainloop()

As u can see, I set the button anchor(I mean x=200, y=150) at the center of the frame, and the anchor's value is NW. The button should be placed in top left corner of the frame, but it turned out at bottom right corner of it, it's totally reversed. I am so confused, and I try my best to look out in google, but it seems like no one has the same question as me, if anyone could help me out please?

The anchor specifies the part of the button that is to appear at the given coordinates. Setting the anchor to NW means that the northwest corner of the button is to appear at the given coordinates.

You've set the coordinates at 200,150, so the upper-left corner of the widget will be placed at that position, and that's exactly what is happening.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM