- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How do I change the background of a Frame in Tkinter?
In order to change the background color and foreground color of a tkinter frame, we can assign different values to the bg and fg parameters in the Frame function.
Example
In this example, we have created two frames with different background colors.
#Import the required libraries from tkinter import * #Create an instance of tkinter frame win= Tk() #Set the geometry of frame win.geometry("650x250") #Create an frame frame1= Frame(win, bg= "red") frame2= Frame(win, bg="black") #Create an label inside the frame Label(frame2, text= "Line:1", font=('Lucida font',20)).pack(pady=20) Label(frame1, text= "Line:2", font=('Lucida font',20)).pack(pady=20) frame1.pack() frame2.pack() win.mainloop()
Output
Running the above code will display a window containing two frames with different background colors.
Advertisements