
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Create Transparent Widgets Using Tkinter
A Tkinter widget in an application can be provided with Transparent background. The background property of any widget is controlled by the widget itself.
However, to provide a transparent background to a particular widget, we have to use wm_attributes('transparentcolor', 'colorname') method. It works in the widget only after adding the same transparent color as the background color of the widget.
Example
#Import the required libraries from tkinter import * #Create an instance of Tkinter Frame win = Tk() #Set the geometry win.geometry("700x250") #Adding transparent background property win.wm_attributes('-transparentcolor', '#ab23ff') #Create a Label Label(win, text= "This is a New line Text", font= ('Helvetica 18'), bg= '#ab23ff').pack(ipadx= 50, ipady=50, padx= 20) win.mainloop()
Output
When we compile the above code, it will display a window with a Label widget in transparent background.
Advertisements