Python tkinter Simple Layout Example Tutorial

Source: Internet
Author: User
This example shows the Python Tkinter method for implementing a simple layout, with more detailed comments in the sample for easy reading. Share it for everyone's reference. Specific as follows:

#-*-Coding:utf-8-*-from Tkinter Import *root = Tk () # 80x80 represents the size of the main window at initialization, 0, 0 represents the location of the window at the time of initialization root.geometry (' 80x80+10+10 ' # Fill in Direction ' ' label (root, Text = ' L1 ', bg = ' red '). Pack (fill = Y) label (root, Text = ' L2 ', bg = ' green '). Pack (fill = BOTH) label (root, Text = ' L3 ', bg = ' blue '). Pack (fill = X) # Around layout label (root, Text = ' L1 ', bg = ' red '). Pack (fill = Y, side = left) label  (root, Text = ' L2 ', bg = ' green '). Pack (fill = BOTH, side = right) Label (root, Text = ' L3 ', bg = ' blue '). Pack (fill = X, side = left) # Absolute Layout L4 = label (root, Text = ' L4 ') l4.place (x = 3, y = 3, anchor = NW) ' ' # grid grid layout L1 = label (root, Text = ' L1 ', BG = ' Red ') L2 = label (root, Text = ' L2 ', bg = ' blue ') L3 = label (root, Text = ' L3 ', bg = ' green ') L4 = label (root, Text = ' L 4 ', bg = ' yellow ') L5 = Label (root, Text = ' L5 ', bg = ' Purple ') l1.grid (row = 0, column = 0) l2.grid (row = 1, column = 0) l3.g RID (row = 1, column = 1) l4.grid (row = 2) l5.grid (row = 0, column = 3) root.mainloop ()

The grid grid layout works as shown in the following:

Interested readers can test the results of this example, I believe that everyone's Python program design has some reference value.

  • 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.