tkinter 12 frame
Reference
- http://effbot.org/tkinterbook/frame.htm
- http://bbs.fishc.com/thread-59339-1-1.html
简介
Frame就是屏幕上的一块矩形区域,多是用来作为容器(container)来布局窗体,为其他组件提供艰巨填充。同时,它也可以被当作容器来播放视频,或者作为分割装饰,
- background, bg, (背景颜色)
- borderwidth, bd, (边框宽度,默认0)
- height, width, (高宽)
- relief(形状),SUNKEN, RAISED, GROOVE, RIDGE
- cursor,(设置鼠标经过时的样式)
- container, (如果设为TRUE,意味着将作为容器,一些其他应用程序可以被嵌入,默认为False)
- class(默认就是Frame),
- takefocus (组件是否接受焦点(通过tab切换),默认是False)
- colormap, (设置颜色映射)
- highlightbackground,highlightcolor, highlightthickness,
例子1-布局窗体
def _gui_int(self):
i, i_row = 0, 0
tk.Frame(self.window,
bg='#080808',
width=300,
height=50,
bd=2).grid(row=i_row,
column=0,
columnspan=3)
color_lst = ['red', 'blue', 'yellow', 'green',
'white', 'black', '#900977', '#343434', '#199206']
for color in color_lst:
i_row = i // 3 + 1
i_col = i % 3
tk.Frame(self.window,
height=50,
width=100,
bg=color,
bd=2).grid(row=i_row, column=i_col)
i += 1
status_bar = tk.Frame(self.window, bg='#080808', width=300, height=50, bd=2)
status_bar.grid(row=i_row+1, column=0, columnspan=3)
tk.Label(status_bar,
text="Copyright \N{COPYRIGHT SIGN} 2018 Zhen ZHAO",
bg='red',
fg='white').pack(side='right', anchor='e')
例子2-分割符
from tkinter import *
master = Tk()
master.geometry('300x100')
Label(text="one").pack()
separator = Frame(height=2, bd=1, relief=SUNKEN, bg='red')
separator.pack(fill=X, padx=5, pady=5)
Label(text="two").pack()
mainloop()