一、pack() pack()有以下几个常用属性: side padx pady ipadx ipady fill expand 1,side side属性有四个可选值:'top'、'bottom'、'left'、'right',分别表示将控件位置设在窗口顶部中心、底部中心、左边中心、右边中心。side默认值为'top'。 2,padx、pady、ipadx、ipady 这四个属性分别设置控件水平方向...
tk.Button(windows,text='A').pack(side='left',expand='yes',fill='y') tk.Button(windows,text='B').pack(side='top',expand='yes',fill='x') tk.Button(windows,text='C').pack(side='right',expand='yes',fill='none') tk.Button(windows,text='D').pack(side='bottom',expand='yes',...
一共有三种布局方式:pack、grid、place: pack布局,直接使用pack函数就可以了。 1.默认先使用的放到上面,然后 依次向下排,它会给我们的组件一个自认为合适的位置和大小 2.也可使用参数: side:指定了它停靠在哪个方向,可以为LEFT,TOP,RIGHT,BOTTOM,分别代表左,上,右,下 fill:X,Y,BOTH和NONE,即在水平方向填充,...
pack布局 1importtkinter23 wuya =tkinter.Tk()4 wuya.title("wuya")5 wuya.geometry("300x200+10+20")678#fill控制填充方式9 lb1 =tkinter.Label(wuya,10 text='wuya good good study',11 bg='red',12)13 lb1.pack(fill=tkinter.X)141516#padding 控制边距,如果不设置则默认为017#padx,设置x方向的...
fg="white").pack(fill=X) #fill选项是设置横向填充4Label(root,text="red",bg="green",fg="black").pack(fill=X)5Label(root,text="red",bg="blue",fg="white").pack(fill=X)67# Label(root,text="red",bg="red",fg="white").pack(side=RIGHT)#如果想将组件整体横向排序,可以设置side选择...
tk.Label(window,text='123mn你好',fg='red').pack(side='bottom') # 下 会表示为2个Label部件。 w=tk.Label(window,text='123mn你好',fg='red') w.pack(side='top') w.pack(side='bottom') 却只表示1个Label部件,只取最后的bottom。
side 顺次放置控件 我们把上面那几个 Label 从左到右放在一排: 1 2 3 4 5 6 7 8 9 10 11 12 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="bla...
imgLabel.pack(side=tk.RIGHT)#自动对齐 def callback():#触发的函数 var.set("你还真按了")#设置文字 #[frame]所属框架 ,text 文字内容 command:触发方法 theButton = tk.Button(frame2,text="我是下面的按钮",command=callback) theButton.pack()#自动对齐 ...
pack() btn = tkinter.Button(win, text="点击", command=showInfo) btn.pack() 带滚动条的 Text 控件 代码语言:javascript 复制 t = tkinter.Text(win, width=60, height=10) sc = tkinter.Scrollbar() # 滚动条 # side 控件放置在窗体的那一侧,fill 填充方向 sc.pack(side=tkinter.RIGHT, fill=...
pack(side="left", fill="both") sb.config(command=lb.yview) # 窗体循环 root.mainloop() Toplevel/PanedWindow/Frame # coding:utf-8 import tkinter as tk from tkinter import ttk # 创建窗体 root = tk.Tk() # 改变窗体名 root.title('Toplevel') # 更改窗体大小 root.geometry('600x400+300+...