- Tkinter GUI Application Development Cookbook
- Alejandro Rodas de Paz
- 264字
- 2021-08-27 19:44:10
How it works…
The first label is placed with the relwidth and relheight options set to 0.25, which means that its width and height are 25% of its parent container. By default, widgets are placed at the x=0 and y=0 positions and aligned to north-west, that is, the top-left corner of the screen.
The second label is placed at the absolute position—x=100—and aligned to the top border with the anchor option set to the tk.N (north) constant. Here, we also specified an absolute size with width and height.
The third label is centered on the window using the relative positioning and setting the anchor to tk.CENTER. Remember that a value of 0.5 for relx and relwidth means half of the parent's width and a value of 0.5 for rely, and relheight means half of the parent's height.
The fourth label is placed on top of label_c by passing it as the in_ argument (note that Tkinter suffixes it with an underscore because in is a reserved keyword). When using in_, you might notice that the alignment is not geometrically exact. In our example, we had to add an offset of 2 pixels in each direction to perfectly overlap the right-bottom corner of label_c.
Finally, the fifth label uses absolute positioning and relative size. As you may have already noticed, these dimensions can be easily switched since we assume a parent container of 200 x 200 pixels; however, only relative weights will work as expected if the main window is resized. You can test this behavior by resizing the window.
- 極簡(jiǎn)算法史:從數(shù)學(xué)到機(jī)器的故事
- ASP.NET Core:Cloud-ready,Enterprise Web Application Development
- Python快樂(lè)編程:人工智能深度學(xué)習(xí)基礎(chǔ)
- 青少年軟件編程基礎(chǔ)與實(shí)戰(zhàn)(圖形化編程三級(jí))
- Python Tools for Visual Studio
- Haxe Game Development Essentials
- Mastering openFrameworks:Creative Coding Demystified
- Visual Basic程序設(shè)計(jì)上機(jī)實(shí)驗(yàn)教程
- 響應(yīng)式架構(gòu):消息模式Actor實(shí)現(xiàn)與Scala、Akka應(yīng)用集成
- 圖數(shù)據(jù)庫(kù)實(shí)戰(zhàn)
- Scala編程(第5版)
- Vue.js光速入門(mén)及企業(yè)項(xiàng)目開(kāi)發(fā)實(shí)戰(zhàn)
- 計(jì)算機(jī)組裝與維護(hù)(第二版)
- SCRATCH編程課:我的游戲我做主
- HikariCP數(shù)據(jù)庫(kù)連接池實(shí)戰(zhàn)