Movatterモバイル変換


[0]ホーム

URL:


Open In App
Next Article:
How to remove text from a label in Python?
Next article icon

Tkinter is a Python module which is used to create GUI (Graphical User Interface) applications. It is a widely used module which comes along with the Python. It consists of various types of widgets which can be used to make GUI more user-friendly and attractive as well as functionality can be increased. LabelFrame can be created as follows:

->import tkinter->create root->create LabelFrame as child of root
label_frame = ttk.LabelFrame(parent, value = options, ...)

Code #1: Creating LabelFrame and adding a message to it. 

Python3
# Import only those methods# which are mentioned below, this way of# importing methods is efficientfromtkinterimportTk,mainloopfromtkinter.ttkimportLabel,LabelFrame# Creating tkinter window with fixed geometryroot=Tk()root.geometry('250x150')# This will create a LabelFramelabel_frame=LabelFrame(root,text='This is Label Frame')label_frame.pack(expand='yes',fill='both')label1=Label(label_frame,text='1. This is a Label.')label1.place(x=0,y=5)label2=Label(label_frame,text='2. This is another Label.')label2.place(x=0,y=35)label3=Label(label_frame,text='3. We can add multiple\n    widgets in it.')label3.place(x=0,y=65)# This creates an infinite loop which generally# waits for any interrupt (like keyboard or# mouse) to terminatemainloop()

Output:   Code #2: AddingButton andCheckButton widgets inside LabelFrame. 

Python3
# Import only those methods# which are mentioned below, this way of# importing methods is efficientfromtkinterimportTk,mainloopfromtkinter.ttkimportCheckbutton,Button,LabelFrame# Creating tkinter window with fixed geometryroot=Tk()root.geometry('250x150')# This will create a LabelFramelabel_frame=LabelFrame(root,text='This is Label Frame')label_frame.pack(expand='yes',fill='both')# Buttonsbtn1=Button(label_frame,text='Button 1')btn1.place(x=30,y=10)btn2=Button(label_frame,text='Button 2')btn2.place(x=130,y=10)# Checkbuttonschkbtn1=Checkbutton(label_frame,text='Checkbutton 1')chkbtn1.place(x=30,y=50)chkbtn2=Checkbutton(label_frame,text='Checkbutton 2')chkbtn2.place(x=30,y=80)# This creates infinite loop which generally# waits for any interrupt (like keyboard or# mouse) to terminatemainloop()

Output:Note: One can also add anotherLabelFrameinside anotherLabelFrame,as well as one can do styling of anyLabelFramelike we do the styling of other widgets.


Improve
Practice Tags :

Similar Reads

We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood ourCookie Policy &Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences

[8]ページ先頭

©2009-2025 Movatter.jp