tkinter 的pack()可以设置的属性如下:

pack_configure(self, cnf={}, **kw)Pack a widget in the parent widget. Use as options:


after=widget - pack it after you have packed widget
anchor=NSEW (or subset) - position widget according to
                          given direction
before=widget - pack it before you will pack widget
expand=bool - expand widget if parent size grows
fill=NONE or X or Y or BOTH - fill widget if widget grows
in=master - use master to contain this widget
in_=master - see 'in' option description
ipadx=amount - add internal padding in x direction
ipady=amount - add internal padding in y direction
padx=amount - add padding in x direction
pady=amount - add padding in y direction
side=TOP or BOTTOM or LEFT or RIGHT -  where to add this widget.

中文解释如下:

anchor=NSEW,表示设置我们要加的当前部件的位置

side=TOP or BOTTOM or LEFT or RIGHT  表示在父类容器的什么地方家我们的部件

Python 入坑的pack()方法:

 #coding:utf-8
import tkinter
# 导入TK的符号常亮
from tkinter.constants import * def sendStr():
print('Data Send Ok!') # 实例化TK类,主窗口必须为.TK(),而其他子窗口为.Toplevel()
top = tkinter.Tk() # 设置窗口的尺寸大小
top.wm_geometry('320x480+1000+100') # 不允许 改变 窗口的宽和高
top.wm_resizable(False,False) # 设置窗口标题
top.title('TCP Server') # 设置label标签
L1 = tkinter.Label(top, text='TCP Sever;\n20108/09/15',
width=15, justify=LEFT, relief=RIDGE, background='#6699ff', )\
.pack_configure(anchor=S, side=TOP, ipady=2, pady=2, fill=NONE) # 设置容器
frame1 = tkinter.Frame(top,height=80,width=60,relief=RIDGE, bg='#ff3399',bd=5,borderwidth=4)
# 设置填充和布局
frame1.pack(fill=NONE,ipady=2,expand=False) # 添加接收区文字标签
L2 = tkinter.Label(frame1,text='接\n收\n区',width=2, justify=LEFT, font=("宋体", 12, "bold"),)\
.pack(padx=2,pady=40,side=LEFT,anchor=N) # 添加接收区的文本框
txt1 = tkinter.Text(frame1,width = 40, height = 10).pack(padx=2,pady=10,side=RIGHT,anchor=N) frame2 = tkinter.Frame(top, relief=RIDGE,bg='#3366ff')
frame2.pack(fill=X, padx=2,pady=10,side=TOP) # 加一个复选框,一个按键
chk_text = 'Hex Display'
int_if_choise = tkinter.IntVar()
chk1 = tkinter.Checkbutton(frame2,text=chk_text,font=('黑体',12),variable=int_if_choise,onvalue='OK',offvalue='NO')
chk1.pack(fill=NONE,side=LEFT,padx=2,pady=10)
print('shuchu:',int_if_choise) # 设置容器
frame3 = tkinter.Frame(top,height=120,width=60,relief=RIDGE, bg='#ff3399',bd=5,borderwidth=4)
# 设置填充和布局
frame3.pack(fill=X,ipady=2,expand=False) # 设置字符串变量
ServerReceiveVar = tkinter.StringVar(top,'') L3 = tkinter.Label(frame3, text='Cache&Input:',font=('黑体',12))
L3.pack(fill=NONE, expand=NO, side=TOP, anchor=W, padx=2,pady=10) txt2 = tkinter.Text(frame3, height = 2, width = 30).pack(padx=2, pady=2, ipady=4, side=LEFT, anchor=N) button1 = tkinter.Button(frame3,text='Send Str', command=sendStr).pack(side=TOP, anchor=W, padx=2, pady=4) # IP 列表
button2 = tkinter.Button(frame3,text="Exit",command=top.destroy).pack(side=TOP, anchor=N, padx=2, pady=10) top.mainloop()

 from Tkinter import *

 root = Tk()

 w = Label(root, text="red", bg="red", fg="white")
w.pack(padx=5, pady=10, side=LEFT)
w = Label(root, text="green", bg="green", fg="black")
w.pack(padx=5, pady=20, side=LEFT)
w = Label(root, text="blue", bg="blue", fg="white")
w.pack(padx=5, pady=20, side=LEFT) mainloop()

dd

python之tkinter入坑Pack()------(1)的更多相关文章

  1. win7 python pdf2image入坑经历

    Python开发菜鸟入坑 项目要求pdf转成图片,网上较多的方案对于windows极其不友好,wand,Pythonmagick(win下载地址:www.lfd.uci.edu/~gohlke/pyt ...

  2. [Python]Python入坑小项目推荐- Flask example minitwit

    知乎上看到的Python练手项目推荐,链接见:https://www.zhihu.com/question/29372574,不知道是我自己懒得看还是理解力不行,这些项目真的是...太大了呀~~~~ ...

  3. python函数中把列表(list)当参数时的"入坑"与"出坑"

    在Python函数中,传递的参数如果默认有一个为 列表(list),那么就要注意了,此处有坑!! 入坑 def f(x,li=[]): for i in range(x): li.append(i*i ...

  4. python使用tkinter无法给顶层窗体的输入框设定默认值

    这几天某同学遇到了一个棘手的问题,困扰了很久.今天终于解决了,我来记录一下坑. 情景:python 使用tkinter为第二层窗体(顶层窗体)中的一个输入框设定默认值时,总是无法设置,而且对输入框获取 ...

  5. ReactNative for Android入坑(一)

    最近找工作发现有些公司要求会ReactNative,决定入坑. 搭建环境:官网详细的教程附链接. 坑一:FQ,建议整个搭建过程中FQ.(FQ链接,注册有200M试用流量,环境搭建够了)第一步:安装Ch ...

  6. Python GUI - Tkinter tkMessageBox

    Python GUI - Tkinter tkMessageBox: tkMessageBox模块用于显示在您的应用程序的消息框.此模块提供了一个功能,您可以用它来显示适当的消息     tkMess ...

  7. Python GUI - tkinter

    目录: Tkinter 组件 标准属性 几何管理 代码实例: 1. Label & Button 2. Entry & Text 3.Listbox列表 4.Radiobutton单选 ...

  8. python中的这些坑,早看早避免。

    python中的这些坑,早看早避免. 说一说python中遇到的坑,躲坑看这一篇就够了 传递参数时候不要使用列表 def foo(num,age=[]): age.append(num) print( ...

  9. c#调用c++ dll 入坑记录

    1.DLL引用坑 [DllImport("NetDLL.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConve ...

随机推荐

  1. 【grafana报错】Singlestat "Error: Multiple Series Error"

    这个错误是因为grafana中的单值面板在同一个时刻读到了多个值.需要检查面板的json源码,检查其expr字段中的promql表达式是否会在同一时刻返回多个值. https://github.com ...

  2. 【转】do...while(0)的妙用

    前言 今天无意中看到这个标题,因为好奇就点进去了,不错,又学习啦... 具体内容: 1. do...while(0)消除goto语句: 2 宏定义中的do...while(0): 参考 1. 原链接_ ...

  3. CSS3 《3D骰子 压大小》

    游戏在线预览地址:http://dtdxrk.github.io/game/3d-dice/index.html js判断一个随机数大小的游戏. 本来想用canvas做的,平面的生产一个点数,感觉没啥 ...

  4. 微信公众号使用vue,安卓端点击按钮404,ios访问正常问题

    情景:微信公众号使用vue开发的单页面,在安卓端点击按钮访问显示404,ios访问正常问题,能正常显示. 解决:将微信公众号菜单按钮设置的路径中把WWW去掉后,安卓.ios都能正常访问. 问题路径ww ...

  5. git和GitHub初级

    使用方式: 一种是本地创建一个文档, 然后在github上创建一个仓库, 在上传上去 一种是从仓库下载代码, 然后在本地编辑, 然后在上传上去 第一种: 首先在linux上创建一个文档, mkdir ...

  6. docker安装MongoDB创建用户,并用工具Robo连接简单CRUD

    搜索mongo docker search mongo 拉取mongo[这里默认为latest] docker pull mongo 查看本地镜像 启动容器[就是安装,-v后面的参数表示把数据文件挂载 ...

  7. 配置jdbc问题 mysql与IDEA

    1.新建lib文件夹,将jar文件导入 2在structure中添加jar文件 3设置url时需要设置时区: import java.sql.Connection;import java.sql.Dr ...

  8. twemproxy配置

    redis多主从,多节点,读写分离架构. nutcracker.yml的twemproxy配置 #redis_main是twemproxy所控制redis主从集群逻辑名称 redis_main: #t ...

  9. Linux shell 中 & && [] [[]] () [] 含义

    | 语法:command 1 | command 2 功能:把第一个命令 command 1 执行的结果作为 command 2 的输入传给 command 2 & & 放在启动参数后 ...

  10. zblog常用到的几个标签介绍

    文章归档 <divclass="function"id="divArchives"> <h3><#ZC_MSG028#>&l ...