
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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.
- Related Questions & Answers
- How do I get the background color of a Tkinter Canvas widget?
- How do I change the overall theme of a tkinter application?
- How do I change the background color of the ActionBar of an ActionBarActivity?
- How to change the background color of a Treeview in Tkinter?
- How to change the background color of a tkinter Canvas dynamically?
- How do I change button size in Python Tkinter?
- How to change the width of a Frame dynamically in Tkinter?
- How do I change the Tkinter default title in the OS bar?
- Dynamically change the widget background color in Tkinter
- Python Tkinter – How do I change the text size in a label widget?
- How to Change Tkinter Frame Title?
- How to make a Button Hover to change the Background Color in Tkinter?
- How do you animate the change of background color of a view on iOS?
- How do you animate the change of background color of a view on Android?
- How do I close a tkinter window?
Advertisements