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

學(xué)無(wú)先后,達(dá)者為師

網(wǎng)站首頁(yè) 編程語(yǔ)言 正文

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

作者:未名編程 ? 更新時(shí)間: 2022-08-11 編程語(yǔ)言

tkinter的錨點(diǎn)(anchor)問題

tkinter中anchor參數(shù)

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

字母 方位
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的含義

關(guān)于place的用法,重點(diǎn)在于理解anchor的用法。

在一個(gè)大矩形中準(zhǔn)確地定義一個(gè)小矩形(有面積,不是點(diǎn))的位置,需要知道三個(gè)信息:一是坐標(biāo)系定義,二是坐標(biāo)數(shù)據(jù),三是要在小矩形上指定一個(gè)定位點(diǎn)。原點(diǎn)和坐標(biāo)系完全是系統(tǒng)默認(rèn)的定義方式,即原點(diǎn)在master控件的左上角,向右向下為正。

坐標(biāo)數(shù)據(jù)以相對(duì)形式給出,取0到1之間的浮點(diǎn)數(shù)。如果取0,則參考點(diǎn)橫坐標(biāo)為0(在最左側(cè)),如果取1,則參考點(diǎn)橫坐標(biāo)為master控件的最右側(cè),縱坐標(biāo)也是如此。

定位點(diǎn)anchor的定義,這個(gè)是最終定位的關(guān)鍵。如圖:

如圖,定義位置時(shí),以master控件的左上角為原點(diǎn),以給定的相對(duì)坐標(biāo)(這里都是0.5)指定位置。

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

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

再如:

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

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

欄目分類
最近更新