Python Tkinter Frame
Python Tkinter Frame
tkinter的Frame组件:这个组件是容器组件,用于在复杂布局中将其他的组件分组。
所谓容器组件,就是可以收纳其它组件,可以做其它组件的父组件的组件。
frame的属性:
bg 或 background : frame组件的背景颜色
bd 或 borderwidth : frame的边框宽度,默认值为2像素
width : frame组件的宽度,默认值为0
height : frame组件的高度,默认值为0
padx : frame的X方向的内边距,默认值为0
pady : frame的Y方向的内边距,默认值为0
relief : frame的样式
from tkinter import * root=Tk() root.geometry ( '300x150+888+444') frl=Frame(root)# 创建一个框架 Frame frl.pack() root.mainloop()
from tkinter import * root1 = Tk() for fm in ['violet', 'indigo', 'blue', 'green', 'yellow','orange','red']: Frame(height = 25,width = 740,bg = fm).pack() root1.mainloop()
from tkinter import * root = Tk() frame1 = Frame(root, highlightbackground="blue", highlightthickness=1,width=600, height=100, bd=10) frame1.pack() root.mainloop()
from tkinter import * root=Tk() root.geometry ( '300x150+888+444') fr1=Frame(root,width=100,height=50,bg='lightgreen')#第4行代码,创建一个框架 Frame fr1.pack() root.mainloop()
from tkinter import * root=Tk() root.geometry ( '300x150+888+444') fr1=Frame(root,width=100,height=50,bg='lightgreen', borderwidth=5, relief="ridge")#第4行代码,创建一个框架 Frame fr1.pack() root.mainloop()
Relief styles
The relief style of a widget refers to certain simulated 3-D effects around the outside of the widget. Here is a screen shot of a row of buttons exhibiting all the possible relief styles:
The width of these borders depends on the borderwidth
option of the widget. The above graphic shows what they look like with a 5-pixel border; the default border width is 2.
序号 | 可选项 & 描述 |
---|---|
1 |
bg 框架背景颜色 |
2 |
bd 框架的大小,默认为 2 个像素 |
3 |
cursor 鼠标移动到框架时,光标的形状,可以设置为 arrow, circle, cross, plus 等。 |
4 |
height 框架的高度,默认值是 0。 |
5 |
highlightbackground 框架没有获得焦点时,高亮边框的颜色,默认由系统指定。 |
6 |
highlightcolor 框架获得焦点时,高亮边框的颜色 |
7 |
highlightthickness 指定高亮边框的宽度,默认值为 0不带高亮边框) |
8 |
relief 边框样式,可选的有:FLAT、SUNKEN、RAISED、GROOVE、RIDGE。默认为 FLAT。 |
9 |
width 设置框架宽度,默认值是 0。 |
10 |
takefocus 指定该组件是否接受输入焦点(用户可以通过 tab 键将焦点转移上来),默认为 false。 |
- bg: The Tkinter frame’s bg option is the normal bg( background color ), which is used to display behind the indicator and the label.
- bd: The Tkinter frame’s bd option is very much helpful in setting the border size around the indicator, and by default, its size is only 2 pixels.
- cursor: The “cursor” option helps set this cursor option to a cursor name ( dot, arrow, etc.. ). With this mouse cursor’s help, it will help change the pattern when the cursor/mouse point is over the checkbutton/ we can call it as changing the pattern when the checkbutton is below the cursor point.
- height: The “height” option of this is only the new frame’s vertical dimension.
- highlightbackground: The “highlightbackground” option of the Tkinter frame is the focus highlight’s color when the frame don’t have any focus.
- highlightcolor: The “highlightcolor” option of the Tkinter frame only shows the color in the focus highlight when there is a focus for the frame.
- highlightthickness: The “highlightthickness” option is the focus highlight’s thickness.
- relief: The “relief” option of the Tkinter frame is the only checkbutton which don’t even stand out from the background, and by default, the relief value is FLAT (relief = FLAT). You can set this option to all of the other styles.
- width: The “width” option of the Tkinter frame is the checkbutton’s width which is the size of the text or the image by default. One can also use this option to the number of the characters, and this width checkbutton also have room for many characters always.
————————————————
REF
https://www.runoob.com/python/python-tk-frame.html
https://tkdocs.com/shipman/ttk-Frame.html
https://www.educba.com/tkinter-frame/#:~:text=relief%3A%20The%20%E2%80%9Crelief%E2%80%9D%20option%20of%20the%20Tkinter%20frame,this%20option%20to%20all%20of%20the%20other%20styles.
https://blog.csdn.net/hyf64/article/details/121259489