Creating a LabelFrame inside a Tkinter Canvas

Last updated Dec 31, 2021

Tkinter Label Frame widgets are one of the most popular widgets used to make high-level Graphical User Interface applications. There are many other widgets built into Tkinter. The LabelFrame widget lets you add a labeled frame to your apps. When you use this LabelFrame, you can add text or an image to a container or a frame that you want.

Generally, the LabelFrame widget has two main parts:

·         The text of the LabelFrame widget, which shows the Title Bar.

·         The LabelFrame widget has text that tells you what's inside the frame. This part can be filled with text and images.

 

Creating a LabelFrame within a Tkinter Canvas

To build a LabelFrame, use the following simple syntax

import tkinter

parent root

 LabelFrame as child of root

label_frame = ttk.LabelFrame(parent, value = options, ...)

 

 

When creating a LabelFrame widget,  you should  define  the constructors  of the  LabelFrame(root) widget.

 

Example

In this code snippet, we are going to display a LabelFrame within a Tkinter Canvas

from tkinter import *

win = Tk()

win.geometry("500x250")

canvas= Canvas(win)

canvas.pack()

lf = LabelFrame(canvas,text= "A LabelFrame")

label= Label(lf, text= "I have created a LabelFrame.")

label.config(font= 'Arial 12')

label.pack(padx=20, pady=20)

lf.pack()

win.mainloop()

 

Lable fram inside canvas tkinter python

 

 

Download Source code

 

Article Contributed By :
https://www.rrtutors.com/site_assets/profile/assets/img/avataaars.svg

386 Views