栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Python的tkinter中控制组件的位置

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Python的tkinter中控制组件的位置

部分代码转载:某博主部分代码

from tkinter import *


class App:
    def __init__(self, master):
        fm1 = frame(master)                                  # 使用frame产生第二层容器,Tk()只能提供一层
        # Button是一种按钮组件,与Label类似,只是多出了响应点击的功能
        Button(fm1, text='Top').pack(side=TOP,  fill=X)  # fill功能不太清楚
        Button(fm1, text='Center').pack(side=TOP, fill=X)
        Button(fm1, text='Bottom').pack(side=TOP, fill=X)
        fm1.pack(side=LEFT, pady=10)                         # 结合pack的side参数控制每层容器的位置
        # fm1.pack(anchor=W)

        fm2 = frame(master)
        Button(fm2, text='Left').pack(side=LEFT)
        Button(fm2, text='This is the Center button').pack(side=LEFT)  # 二层中小层左左分布,也是左右分布
        Button(fm2, text='Right').pack(side=LEFT)
        fm2.pack(side=RIGHT, padx=10)                        # 一二层容器是左右分布


root = Tk()
root.title("Pack - Example")
display = App(root)
root.mainloop()

结果:

结论:

frame()类产生第二层容器,pack()控制大容器小容器的位置

联合可以控制组件的位置

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/269509.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号