Python tkinter frame

Basics of Python Tkinter

Managing widgets in a group and providing separators by using frame.

Understanding frame

Tkinter side=LEFT
import tkinter as tk
from tkinter import * 
my_w=tk.Tk()

my_bottom=Frame(my_w,background='red')
my_bottom.pack(side=BOTTOM)

b1=tk.Button(my_w,text='b1')
b1.pack(side=LEFT)

# Using Frame by_bottom
b2=tk.Button(my_bottom,text='b2')
b2.pack(side=LEFT)

b3=tk.Button(my_bottom,text='b3')
b3.pack(side=LEFT)
l4=tk.Label(my_bottom,text='l4 label')
l4.pack(side=LEFT)
b4=tk.Button(my_bottom,text='b4')
b4.pack(side=LEFT)
l5=tk.Label(my_bottom,text='l5 label')
l5.pack(side=LEFT)

my_w.mainloop()

Config options side

backgroundBackground colour to use, check the Output in above code for red background
bgSame as background
borderwidthWidth of the border of the Frame ( check examples below )
bdSame as borderwidth
classAssign class , default is Frame
colormapspecify which color map to use
containerDefault is 0
cursorList of cursor shape is available here . The shape of mouse pointer to be displayed over the frame
heightDefault is 0
highlightbackgroundDefault is system specific
highlightcolorDefault is system specific
highlightthicknesDefault is 0
padxHorizontal padding, Default is 0
padyVertical padding, Default is 0
reliefFLAT ( default ), SUNKEN, RAISED, GROOVE,RIDGE . The border decoration
takefocusIf true , tab can be used to move focus, Default is 0
visualNo Default
widthDefault is 0

Example

Tkinter frame config
import tkinter as tk
from tkinter import * 
my_w=tk.Tk()

my_bottom=Frame(my_w,bg='green',cursor='boat',bd=20,relief=RAISED,
                width=100,padx=10,pady=10,highlightcolor='yellow')
my_bottom.pack(side=BOTTOM)

b1=tk.Button(my_w,text='b1', width=30)
b1.pack(side=LEFT)

# Using Frame by_bottom
b2=tk.Button(my_bottom,text='b2')
b2.pack(side=LEFT)


b3=tk.Button(my_bottom,text='b3')
b3.pack(side=LEFT)
l4=tk.Label(my_bottom,text='l4 label')
l4.pack(side=LEFT)

my_w.mainloop()

separator

Tkinter frame separator
import tkinter as tk
from tkinter import * 
my_w=tk.Tk()

b1=tk.Button(my_w,text='b1', width=10)
b1.pack(side=TOP)

# Using Frame by_bottom
b2=tk.Button(my_w,text='b2')
b2.pack(side=TOP)
my_line=Frame(my_w,bg='green',bd=20,height=5,width=20,
              relief=RAISED,highlightcolor='yellow')
my_line.pack(side=TOP,fill=X)

b3=tk.Button(my_w,text='b3')
b3.pack(side=BOTTOM)
l4=tk.Label(my_w,text='l4 label')
l4.pack(side=BOTTOM)

my_w.mainloop()
View and Download tkinter-frame ipynb file ( .html format )


Grid Layout in Tkinter Python Tkinter pack


plus2net.com



Post your comments , suggestion , error , requirements etc here




We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2020 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer