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

python的GUI编程之tkinter的使用(一)

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

python的GUI编程之tkinter的使用(一)

import tkinter as tk

class App:

    def __init__(self,master):
        self.master = master
        self.initWidget()

    def initWidget(self):
        # 创建第一个容器
        # pack表示布局
        #     """
        #     expand: 是否跟随父容器按比例扩大
        #     fill: 组件沿水平或者垂直方向填充, 如果不加就会使用空白进行填充
        #     ipadx: 内边距 x方向
        #     padx: x方向外边距
        #     pady: y方向外边距
        #     """
        #     w.pack(expand=True)

        fm1 = tk.frame(master=self.master)
        fm1.pack(side=tk.LEFT, fill=tk.BOTH, expand=True, padx=40)

        tk.Button(fm1, text="第一个").pack(side=tk.TOP, fill=tk.BOTH, pady=20)
        tk.Button(fm1, text="第二个").pack(side=tk.TOP, fill=tk.BOTH, expand=tk.YES, pady=20)
        tk.Button(fm1, text="第三个").pack(side=tk.TOP, fill=tk.BOTH, expand=True, pady=20)

        fm2 = tk.frame(master=self.master)
        fm2.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)

        tk.Button(fm2, text="第一个").pack(side=tk.LEFT, fill=tk.Y, expand=True)
        tk.Button(fm2, text="第二个").pack(side=tk.LEFT, fill=tk.Y, expand=True)
        tk.Button(fm2, text="第三个").pack(side=tk.LEFT, fill=tk.Y, expand=True)

        fm3 = tk.frame(master=self.master)
        fm3.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)

        tk.Button(fm3, text="第一个").pack(side=tk.TOP, fill=tk.Y, expand=True)
        tk.Button(fm3, text="第二个").pack(side=tk.TOP, expand=True)
        tk.Button(fm3, text="第三个").pack(side=tk.TOP, expand=True)


root = tk.Tk()
root.title="pack布局"
# 设置窗口的大小
root.geometry("500x500")
App(root)
root.mainloop()

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

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

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