[Python Basics] geometric manager of Tkinter, pythontkinter

Source: Internet
Author: User

[Python Basics] geometric manager of Tkinter, pythontkinter

Tkinter supports three geometric managers: Grid manager, package manager, and location manager.

Tip: Since each manager has its own style of placing small components, it is best not to use multiple managers in the same container. You can use the framework as a sub-container to obtain the expected layout.

 

1. Grid Manager
# Geometric Manager (1) ----- grid manager ''' the grid manager places small components in each unit of an invisible grid. You can place a widget in a specific row or column, or you can use the rowspan and columnspan parameters to place the widget in multiple rows and columns. ''' From tkinter import * class GridManagerDemo: window = Tk () window. title ("Grid Manager Demo") message = Message (window, text = "This Message widget occupies three rows and two columns") message. grid (row = 1, column = 1, rowspan = 3, columnspan = 2) Label (window, text = "First Name :"). grid (row = 1, column = 3) Entry (window ). grid (row = 1, column = 4, padx = 5, pady = 5) Label (window, text = "Last Name :"). grid (row = 2, column = 3) Entry (window ). grid (row = 2, column = 4) Button (window, text = "Get Name "). grid (row = 3, padx = 5, pady = 5, column = 4, sticky = E) window. mainloop () GridManagerDemo ()

 

2. Package Manager
# Geometric Manager (2) ----- Package Manager ''' contains the manager that places one of the widgets on the top of the other or one by one. ''' # First from tkinter import * class PackManagerDemo: def _ init _ (self): window = Tk () window. title ("Pack Mananger Demo 1") Label (window, text = "Blue", bg = "blue "). pack () # fill uses X, Y, and BOTH to fill in the horizontal, vertical, or two-direction space # expand tells the manager to allocate additional space to the small component Label (window, text = "Red", bg = "red "). pack (fill = BOTH, expand = 1) Label (window, text = "Green", bg = "green "). pack (fill = BOTH) window. mainloop () PackManagerDemo () # Second cl Ass PackManagerDemoWithSide: window = Tk () window. title ("Pack Manager Demo 2") # side can be LEFT, RIGHT, TOP, and BOTTOM. The default value is TOP. Label (window, text = "Blue", bg = "blue "). pack (side = LEFT) Label (window, text = "Red", bg = "red "). pack (side = LEFT, fill = BOTH, expand = 1) Label (window, text = "Green", bg = "green "). pack (side = LEFT, fill = BOTH) window. mainloop () PackManagerDemoWithSide ()

 

3. Location Manager
# Geometric Manager (3) ----- Location Manager ''' the location manager places the widget in an absolute position. '''From tkinter import * class PlaceManagerDemo: def _ init _ (self): window = Tk () window. title ("Place Manager Demo") Label (window, text = "Blue", bg = "blue "). place (x = 20, y = 20) Label (window, text = "Red", bg = "red "). place (x = 50, y = 50) Label (window, text = "Green", bg = "green "). place (x = 80, y = 80) window. mainloop () PlaceManagerDemo ()

 

 



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.