前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >python tkinter 常用组件封装

python tkinter 常用组件封装

作者头像
用户5760343
发布2022-05-13 10:48:22
8280
发布2022-05-13 10:48:22
举报
文章被收录于专栏:sktj

""" wrap up widget construction in functions for easier use, making some assumptions (e.g., expansion); use extras kw args for width, font/color """

from tkinter import *

def frame(root, side=TOP, extras): widget = Frame(root) widget.pack(side=side, expand=YES, fill=BOTH) if extras: widget.config(extras) return widget

def label(root, side, text, extras): widget = Label(root, text=text, relief=RIDGE) # default config widget.pack(side=side, expand=YES, fill=BOTH) # pack automatically if extras: widget.config(extras) # apply any extras return widget

def button(root, side, text, command, extras): widget = Button(root, text=text, command=command) widget.pack(side=side, expand=YES, fill=BOTH) if extras: widget.config(extras) return widget

def entry(root, side, linkvar, extras): widget = Entry(root, relief=SUNKEN, textvariable=linkvar) widget.pack(side=side, expand=YES, fill=BOTH) if extras: widget.config(extras) return widget

if name == 'main': app = Tk() frm = frame(app, TOP) # much less code required here! label(frm, LEFT, 'SPAM') button(frm, BOTTOM, 'Press', lambda: print('Pushed')) mainloop()

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022-05-13,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档