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

Button cannot wrap around an image #37

Closed
Jsnncls opened this issue Jan 7, 2022 · 2 comments
Closed

Button cannot wrap around an image #37

Jsnncls opened this issue Jan 7, 2022 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@Jsnncls
Copy link

Jsnncls commented Jan 7, 2022

Buttons that has an image will always have a buffer around said image. If the "width" and "height" attributes are used, the button would disappear completely.

Steps to reproduce the image buffer problem:

  1. Create a normal button with a .png file as the image.
    image_2= PhotoImage(file = insert image file here.png, height=48, width=55) self.two = Button(root, image=self.image_2, relief=FLAT, bg='#a9a9a9', command=lambda:self.addNum(num=2), bd=0, highlightthickness=0, borderless=1) self.two.grid(row=5, column=2)

Steps to reproduce the disappearing button problem:

  1. Create a normal button with a .png file as the image, set the width and height to any value.
    image_3= PhotoImage(file = insert image file here.png, height=48, width=55) self.three = Button(root, image=self.image_3, relief=FLAT, bg='#a9a9a9',command=lambda:self.addNum(num=3), width=100, height=200) self.three.grid(row=5, column=3)

Expected behavior
The button wraps around the border of the image, making the button just as big as the image used, not bigger and creating a buffer around the image.

Screenshots
Screen Shot 2022-01-07 at 10 14 45
Image 1: Buffer around the image

Desktop (please complete the following information):

  • OS: macOS
  • Version Big Sur 11.6.1
@Jsnncls Jsnncls added the bug Something isn't working label Jan 7, 2022
@Saadmairaj
Copy link
Owner

Hi Jsnncls! Thanks for mentioning the width / height issue and It will be fixed in the next update hopefully.

However, "button wraps around the border of the image" is not an issue as the tkmacosx button simulates ttk button, not the actual Tkinter button but it can be set by giving some negative padding.

For some reason for width and height, it is not registering them initially for images but you can get away by defining after Button is created like so

from tkinter import Tk, PhotoImage
import tkmacosx as tkm

root = Tk()
image = PhotoImage(file="unnamed.png", width=50, height=50)
root.tmp_image = image
b1 = tkm.Button(root, image=image)
b1.configure(width=100, height=200)
b1.pack()
root.mainloop()

image

And for negative padding, you can do the following

from tkinter import Tk, PhotoImage
import tkmacosx as tkm

root = Tk()
image = PhotoImage(file="unnamed.png", width=50, height=50)
root.tmp_image = image
b1 = tkm.Button(root, image=image, padx=-15, pady=-1)
b1.pack()
root.mainloop()

image

Original Image used in the above example
unnamed

@Jsnncls
Copy link
Author

Jsnncls commented Jan 9, 2022

Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants