日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

python?tkinter中的錨點(anchor)問題及處理_python

作者:未名編程 ? 更新時間: 2022-08-11 編程語言

tkinter的錨點(anchor)問題

tkinter中anchor參數

(注意,參數的英文都是小寫)

字母 方位
n
s
w 西
e
center 中心
nw 西北
ne 東北
sw 西南
se 東南
from tkinter import *
from tkinter import messagebox as box
def 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()

幾何管理方法place中anchor的含義

關于place的用法,重點在于理解anchor的用法。

在一個大矩形中準確地定義一個小矩形(有面積,不是點)的位置,需要知道三個信息:一是坐標系定義,二是坐標數據,三是要在小矩形上指定一個定位點。原點和坐標系完全是系統默認的定義方式,即原點在master控件的左上角,向右向下為正。

坐標數據以相對形式給出,取0到1之間的浮點數。如果取0,則參考點橫坐標為0(在最左側),如果取1,則參考點橫坐標為master控件的最右側,縱坐標也是如此。

定位點anchor的定義,這個是最終定位的關鍵。如圖:

如圖,定義位置時,以master控件的左上角為原點,以給定的相對坐標(這里都是0.5)指定位置。

每個控件都有9個anchor,選一個作為“把手”,將這個“把手”安放在指定位置即可。

anchor='nw’的含義是“將控件的左上角安放在指定位置”。

再如:

anchor='n’的含義是“將控件的上邊中點安放在指定位置”,其他的anchor同理。這可能就是為什么很多python技術文檔中,習慣先指定坐標,最后再選擇anchor。

原文鏈接:https://blog.csdn.net/qq_44275213/article/details/107856794

欄目分類
最近更新