Python pack()方法

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

Python pack()方法

南海有鹏   2022-06-28 我要评论

Python中pack()方法

#Copyright (c)2017, 东北大学软件学院学生
# All rightsreserved
#文件名称:a.py
#  作   者:孔云
#问题描述:用pack()方法不参加排列标签
#问题分析:。代码如下:
from tkinter import *
root=Tk()
lbred=Label(root,text="红色沟槽状边缘",fg="red",font=('微软雅黑',15),width=20,height=2,relief=GROOVE)
lbred.pack()
lbgreen=Label(root,text="绿色凸起的",fg="green",font=('微软雅黑',15),width=20,height=2,relief=RAISED)
lbgreen.pack()
lbblue=Label(root,text="蓝色脊状边缘",fg="blue",font=('微软雅黑',15),width=20,height=2,relief=RIDGE)
lbblue.pack()
lbyellow=Label(root,text="黄色凹陷的",fg="yellow",font=('微软雅黑',15),width=20,height=2,relief=SUNKEN)
lbyellow.pack()
lbpink=Label(root,text="粉红色平的",fg="pink",font=('微软雅黑',15),width=20,height=2,relief=FLAT)
lbpink.pack()
root.mainloop()

运行结果如下:

注:属性relief为控件呈现的3D浮雕样式,有FLAT(平的)、RAISED(凸起的)、SUNKEN(凹陷的)、GROOVE(沟槽状边缘)和RIDGE(脊状边缘)5种。

Python GUI pack方法

from tkinter import *
root = Tk()
root.title("pack方法")
root.geometry("300x180")
print("执行前", root.pack_slaves())
ok_label = Label(root, text="OK",
                 font="Times 20 bold",
                 fg="white", bg="blue")
ok_label.pack(anchor=S, side=RIGHT,
              padx=10, pady=10)
# root.pack_slaves()[0].forget()    # 隐藏控件
ng_label = Label(root, text="NG",
                 font="Times 20 bold",
                 fg="white", bg="red")
ng_label.pack(anchor=S, side=RIGHT,
              pady=10)
print("执行后", root.pack_slaves())
for pack in root.pack_slaves():
    print("info", pack.info())
    print("size", pack.size())
root.mainloop()

以上为个人经验,希望能给大家一个参考,也希望大家多多支持。

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们