網(wǎng)站首頁(yè) 編程語(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
相關(guān)推薦
- 2022-05-18 Python學(xué)習(xí)之自定義異常詳解_python
- 2022-08-11 C#中using關(guān)鍵字的使用方法示例_C#教程
- 2022-05-25 Maven打包時(shí)排除指定的目錄或指定的類
- 2024-07-22 get 、set 、toString 方法的使用
- 2022-01-30 element table表格里的多選按鈕,根據(jù)條件判斷是否可以被選中
- 2022-10-15 Redisson?加鎖解鎖的實(shí)現(xiàn)_Redis
- 2022-07-25 C++文件的操作及小實(shí)驗(yàn)示例代碼詳解_C 語(yǔ)言
- 2022-10-11 React - 判斷焦點(diǎn)是否在某個(gè)元素上
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡(jiǎn)單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對(duì)象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支