小试Python中的pack()使用方法
作者:南海有鹏 时间:2021-02-03 06:00:43
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()
来源:https://blog.csdn.net/u012369559/article/details/78618161
标签:Python,pack
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python数学建模(SciPy+ Numpy+Pandas)
2021-02-17 11:05:14
![](https://img.aspxhome.com/file/2023/2/63622_0s.png)
python实现Nao机器人的单目测距
2021-04-09 16:37:10
纯手工打造CSS像素画
2009-03-09 12:57:00
![](https://img.aspxhome.com/file/UploadPic/20093/9/01-12s.gif)
ASP运行在IIS6 500错误解决办法
2011-04-19 11:15:00
![](https://img.aspxhome.com/file/UploadPic/20112/5/201125111853302s.gif)
修改Linux下MySQL 5.0的默认连接数
2009-09-01 10:16:00
ubuntu中python调用C/C++方法之动态链接库详解
2023-09-07 19:15:55
条件CSS的使用[译]
2009-03-12 12:23:00
![](https://img.aspxhome.com/file/UploadPic/20093/12/01-51s.jpg)
Python自动化测试框架之unittest使用详解
2021-07-02 17:42:27
教你用Python实现简易版学生信息管理系统(含源码)
2022-07-21 23:40:00
网站508规范(译)
2008-04-03 13:26:00
![](https://img.aspxhome.com/file/UploadPic/20084/3/gobuttons_85s.jpg)
柳永法:vbs或asp采集文章时网页编码问题
2009-02-04 10:50:00
通过python实现windows桌面截图代码实例
2023-11-19 03:46:27
一些不错的js函数ajax
2023-08-25 14:01:38
W3C优质网页小贴士(二)
2008-04-07 12:14:00
浅析Banner构成与创意设计
2009-11-28 16:25:00
![](https://img.aspxhome.com/file/UploadPic/200911/28/originality-design-55s.jpg)
Go/Python/Erlang编程语言对比分析及示例代码
2022-08-15 17:19:12
![](https://img.aspxhome.com/file/2023/9/79649_0s.jpg)
Mysql中limit的用法方法详解与注意事项
2023-11-16 09:20:05
Python3爬虫关于识别检验滑动验证码的实例
2021-08-25 02:17:37
![](https://img.aspxhome.com/file/2023/1/89061_0s.png)
Python实现的数据结构与算法之队列详解
2021-06-06 09:58:05
![](https://img.aspxhome.com/file/2023/2/88872_0s.png)
一篇文章弄懂Python关键字、标识符和变量
2022-11-01 17:44:42
![](https://img.aspxhome.com/file/2023/4/66294_0s.png)