网络编程
位置:首页>> 网络编程>> Python编程>> 小试Python中的pack()使用方法

小试Python中的pack()使用方法

作者:南海有鹏  发布时间:2021-02-03 06:00:43 

标签:Python,pack

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()

运行结果如下:

小试Python中的pack()使用方法

注:属性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()

小试Python中的pack()使用方法

来源:https://blog.csdn.net/u012369559/article/details/78618161

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com