Python Tkinter简单布局实例教程
Jun 06, 2016 am 11:32 AM
python
tkinter
layout
本文实例展示了Python Tkinter实现简单布局的方法,示例中备有较为详尽的注释,便于读者理解。分享给大家供大家参考之用。具体如下:
# -*- coding: utf-8 -*- from Tkinter import * root = Tk() # 80x80代表了初始化时主窗口的大小,0,0代表了初始化时窗口所在的位置 root.geometry('80x80+10+10') # 填充方向 ''' 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) # 左右布局 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) # 绝对布局 l4 = Label(root, text = 'l4') l4.place(x = 3, y = 3, anchor = NW) ''' # Grid 网格布局 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 = 'l4', bg = 'yellow') l5 = Label(root, text = 'l5', bg = 'purple') l1.grid(row = 0, column = 0) l2.grid(row = 1, column = 0) l3.grid(row = 1, column = 1) l4.grid(row = 2 ) l5.grid(row = 0, column = 3) root.mainloop()
Copy after login
Grid 网格布局运行效果如下图所示:
感兴趣的读者可以测试一下本文实例运行效果,相信对大家的Python程序设计有一定的借鉴价值。
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot tools Tags

Hot Article
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

What are the advantages and disadvantages of templating?

Google AI announces Gemini 1.5 Pro and Gemma 2 for developers

For only $250, Hugging Face's technical director teaches you how to fine-tune Llama 3 step by step

Share several .NET open source AI and LLM related project frameworks

A complete guide to golang function debugging and analysis
