tkinter The anchor point (anchor) problem
tkinter in anchor Parameters
Geometry management method place in anchor The meaning of
tkinter The anchor point (anchor) problem tkinter in anchor Parameters( Be careful , Parameters are in lowercase in English )
Letter orientation n north s south w In the west e In the east center center nw The northwest ne The northeast sw southwest se Southeastfrom tkinter import *from tkinter import messagebox as boxdef main_menu(): window = Tk() window.title('Juke Box') window.geometry('800x480') window.configure(background = 'black') label = Label(window, text = 'Juke-Box', fg = 'light green', bg = 'black', font = (None, 30), height = 2) label.pack(side = TOP) Jam = Button(window, text = 'The Jam', width = 25, height = 2) Jam.pack(pady = 10, padx = 25, anchor = 'n') Roses = Button(window, text = 'The Stone Roses', width = 25, height = 2) Roses.pack(pady = 10, padx = 25, anchor = 'w') Smiths = Button(window, text = 'The Smiths', width = 25, height = 2) Smiths.pack(pady = 10, padx = 25, anchor = 'w') Wedding = Button(window, text = 'The Wedding Pressent', width = 25, height = 2) Wedding.pack(pady = 10, padx = 25, anchor = 'w') Blondie = Button(window, text = 'Blondie', width = 25, height = 2) Blondie.pack(pady = 10, padx = 25, anchor = 'w') Clash = Button(window, text = 'Clash', width = 25, height = 2) Clash.pack(pady = 10, padx = 25, anchor = 'w') Madness = Button(window, text = 'Madness', width = 25, height = 2) Madness.pack(pady = 10, padx = 25, anchor = 'n') Pistols = Button(window, text = 'The Sex Pistols', width = 25, height = 2) Pistols.pack(pady = 10, padx = 25, anchor = 'n') window.mainloop()main_menu()
Geometry management method place in anchor The meaning of About place Usage of , The point is to understand anchor Usage of .
Accurately define a small rectangle in a large rectangle ( There is an area , Not a little bit ) The location of , There are three things you need to know : The first is the definition of coordinate system , Second, coordinate data , The third is to specify a positioning point on the small rectangle . The origin and coordinate system are completely defined by default , That is, the origin is at master Control , Right down is positive .
Coordinate data are given in relative form , take 0 To 1 The floating point number between . If you take 0, Then the abscissa of the reference point is 0( It's on the far left ), If you take 1, Then the abscissa of the reference point is master Control , So is the ordinate .
Anchor point anchor The definition of , This is the key to the final positioning . Pictured :
Pictured , When defining a location , With master The upper left corner of the control is the origin , With the given relative coordinates ( It's all here 0.5) The specified location .
Every control has 9 individual anchor, Choose one as “ handle ”, Put this “ handle ” It can be placed at the designated position .
anchor='nw’ The meaning is “ Place the upper left corner of the control at the specified position ”.
Again :
anchor='n’ The meaning is “ Place the upper midpoint of the control at the specified position ”, Other anchor Empathy . That may be why so many python In the technical documentation , It is customary to specify coordinates first , Finally, choose anchor.
The above is personal experience , I hope I can give you a reference , I also hope you can support the software development network .