Python技术迷

Tkinter 教程-Python Tkinter 框架(Frame)

整理:python架构师

Python Tkinter 框架小部件用于组织一组小部件。它充当容器,可用于容纳其他小部件。屏幕的矩形区域用于将小部件组织到 Python 应用程序中。

使用框架小部件的语法如下。

语法

w = Frame(parent,  options)

以下是可能的选项列表。

序号选项描述
1bd它表示边框宽度。
2bg小部件的背景颜色。
3cursor当鼠标指针位于其上时,它会更改为不同值,如箭头、点等的光标类型。
4height框架的高度。
5highlightbackground在焦点下时的背景颜色。
6highlightcolor在小部件处于焦点状态时的文本颜色。
7highlightthickness当小部件处于焦点状态时,它指定边框周围的厚度。
8relief它指定边框的类型。其默认值为FLAT。
9width它表示小部件的宽度。

专属福利 

👉点击领取:最全Python资料合集

示例

from tkinter import *  top = Tk()  top.geometry("140x100")  frame = Frame(top)  frame.pack()  leftframe = Frame(top)  leftframe.pack(side = LEFT)  rightframe = Frame(top)  rightframe.pack(side = RIGHT)  btn1 = Button(frame, text="Submit", fg="red",activebackground = "red")  btn1.pack(side = LEFT)  btn2 = Button(frame, text="Remove", fg="brown", activebackground = "brown")  btn2.pack(side = RIGHT)  btn3 = Button(rightframe, text="Add", fg="blue", activebackground = "blue")  btn3.pack(side = LEFT)  btn4 = Button(leftframe, text="Modify", fg="black", activebackground = "white")  btn4.pack(side = RIGHT)  top.mainloop()

输出:

Image
Image
 1
Image
热门推荐
Image