Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Image Opacity #1

Closed
vednig opened this issue Nov 4, 2021 · 7 comments
Closed

Support Image Opacity #1

vednig opened this issue Nov 4, 2021 · 7 comments

Comments

@vednig
Copy link

vednig commented Nov 4, 2021

Code:

trans_label=tkw.Label(root,image='image.png',opacity=0.5)
@vednig
Copy link
Author

vednig commented Nov 4, 2021

Also is there any way to change font or size in Label?

@astqx
Copy link
Owner

astqx commented Nov 15, 2021

Hello, sorry for the late reply.

Images are supported. There is an error in the code provided by you.

There are 2 main methods of displaying images in a Label,

  • tkinter.PhotoImage (simple)

    img = tk.PhotoImage(file='image.png')
    
  • PIL (recommended, as it gives more flexibility)

    from PIL import Image, ImageTk
    img = Image.open('image.png')
    img = ImageTk.PhotoImage(img)
    

And use this with the Label widget

label=tk.Label(root, image=img)
trans_label=tkw.Label(root, image=img, opacity=0.5)

Here's a working example

from tkinter import *
import tkinterwidgets as tkw 
from PIL import ImageTk, Image

root=Tk()
root.config(bg='yellow')

img=Image.open('image.png')
img=img.resize((100,100))
img=ImageTk.PhotoImage(img)

label=Label(root,text='label')
label.pack()

trans_label=tkw.Label(root,image=img,opacity=0.5)
trans_label.image=img
trans_label.pack(pady=10)

root.mainloop()

Reference

@astqx
Copy link
Owner

astqx commented Nov 15, 2021

Yes, there is, please refer to the documentation of the Label widget, it has all the information you need, including what I mentioned above.

@astqx astqx closed this as completed Nov 15, 2021
@vednig
Copy link
Author

vednig commented Nov 15, 2021

And can we have more transparent components like canvas, frames, and buttons?

@vednig
Copy link
Author

vednig commented Nov 15, 2021

Should I open a new issue for this?

And can we have more transparent components like canvas, frames, and buttons?

@vednig
Copy link
Author

vednig commented Nov 15, 2021

I was working on adding transparent background support to rounded buttons in CustomTkinter module.
It would be a great help.🤗

@astqx
Copy link
Owner

astqx commented Nov 16, 2021

And can we have more transparent components like canvas, frames, and buttons?

That's a great idea, I created a more general transparent container, any widget inside it will follow the transparency and opacity rules of the container. It's in the dev branch, I still need to do some testing, if it works perfectly then it would be able to support any component.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants