程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Anchor problem in pythontkinter and its solution

編輯:Python

Catalog

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 Southeast from 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 .



  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved