网站开发表格整体页面居中,怎么对自己的网页进行修改,seo搜索引擎优化实训总结,免费客户管理软件排行在本文中#xff0c;将介绍 tkinter Frame 框架小部件、 LabelFrame 标签框架小部件的使用方法。
Frame 框架
Frame 框架在窗体上建立一个矩形区域#xff0c;作为一个容器#xff0c;用于组织分组排列其他小部件。
要创建框架#xff0c;请使用以下构造函数。
frame …在本文中将介绍 tkinter Frame 框架小部件、 LabelFrame 标签框架小部件的使用方法。
Frame 框架
Frame 框架在窗体上建立一个矩形区域作为一个容器用于组织分组排列其他小部件。
要创建框架请使用以下构造函数。
frame tk.Frame(master, **options)
tkinter 中的每个小部件都需要一个 “parent” 或 “master” 作为第一个参数。当使用框架时要将框架作为其父级。
import tkinter as tk
root tk.Tk()
root.geometry(600x400200200)
root.title(Frame 框架演示)leftframe tk.Frame(root)
leftframe.pack(sidetk.LEFT)rightframe tk.Frame(root)
rightframe.pack(sidetk.RIGHT)button1 tk.Button(leftframe, text Button1)
button1.pack(padx 10, pady 10)
button2 tk.Button(rightframe, text Button2)
button2.pack(padx 10, pady 10)
button3 tk.Button(leftframe, text Button3)
button3.pack(padx 10, pady 10)root.mainloop()在上面的代码中创建了leftframe、 rightframe 两个框架并排左右放置三个按钮小部件分别放置到不同的框架中。 框架也可以作为分隔线使用。
import tkinter as tk
root tk.Tk()
root.geometry(600x400200200)
root.title(Frame 框架演示)
frame1 tk.Frame(root, bd5, relieftk.RIDGE)
frame1.pack(ipadx 100)button1 tk.Button(frame1, text Button1)
button1.pack(padx 10, pady 10)
button2 tk.Button(frame1, text Button2)
button2.pack(padx 10, pady 10)
button3 tk.Button(frame1, text Button3)
button3.pack(padx 10, pady 10)frame2 tk.Frame(frame1, bd5, relieftk.RIDGE, bgblack)
frame2.pack(filltk.X)button4 tk.Button(frame1, text Button1)
button4.pack(padx 10, pady 10)
button5 tk.Button(frame1, text Button2)
button5.pack(padx 10, pady 10)
button6 tk.Button(frame1, text Button3)
button6.pack(padx 10, pady 10)
root.mainloop()LabelFrame 标签框架
tkinter 提供了 Frame 小部件的一个变体称为 LabelFrame。LabelFrame 标签框架除了具备常规框架的功能外还扩展了一些其他功能。
要创建框架请使用以下构造函数。
frame tk.LabelFrame(master, **options)
LabelFrame 标签框架增加了 Text 参数可以作为框架的标题。默认位置在左上角也可以使用参数 labelanchor 改变标题的位置可选参数如下图所示。 使用 labelwidget 参数可以把其他小部件放到框架上。
import tkinter as tk
root tk.Tk()
root.geometry(600x400200200)
root.title(LabelFrame 标签框架演示)button tk.Button(root, text Hello!)
button.pack(padx 5, pady 6)LabelFrame1 tk.LabelFrame(root, textLabelFrame)
LabelFrame1.pack(ipadx 100)LabelFrame2 tk.LabelFrame(root, textLabelFrame, labelanchor se)
LabelFrame2.pack(ipadx 100)LabelFrame3 tk.LabelFrame(root, textLabelFrame, labelanchor s, labelwidget button)
LabelFrame3.pack(ipadx 100)button1 tk.Button(LabelFrame1, text Button1)
button1.pack(padx 10, pady 10)
button2 tk.Button(LabelFrame1, text Button2)
button2.pack(padx 10, pady 10)
button3 tk.Button(LabelFrame2, text Button3)
button3.pack(padx 10, pady 10)button4 tk.Button(LabelFrame2, text Button4)
button4.pack(padx 10, pady 10)
button5 tk.Button(LabelFrame3, text Button5)
button5.pack(padx 10, pady 10)
button6 tk.Button(LabelFrame3, text Button6)
button6.pack(padx 10, pady 10)
root.mainloop()Frame LabelFrame 选项
选项名称说明bd边框的宽度。默认 2 像素。bg背景颜色。cursor鼠标指针类型。height框架的高度。width框架的宽度。highlightbackground背景颜色。highlightthickness获得焦点时边框粗细。relief框架的边框类型。默认 FLAT。highlightcolor获得焦点时高亮颜色。