Santosh
Santosh

Reputation: 19

Python: How to click on an Image button in a window application?

Already I have seen Tkinter library, but I am unable to find a shortcut or at least a way to click on the image button in any window application. This image button is used for uploading a folder.

To click on a specific button, we need the specific property of that button. After trying the below code (with one of a similar threads in StackOverflow regarding buttons in python)

from Tkinter import Button
b = Button()
for k in b.configure().keys():
    print (k, ':', b.cget(k), b.winfo_class())

Output:

('highlightthickness', ':', <pixel object at 0283A930>, 'Button')

But with the output I have got:

  1. I am not sure which property of that image button to use, and
  2. how to code to click that image button.

There is no text seen for this image button in the window application. It is a simple square image button, which only changes a bit in size when hovered over by the cursor.

Please ask if you need any more details regarding the same.

Upvotes: 1

Views: 703

Answers (1)

A J
A J

Reputation: 111

If you really just want a widget, display a button on it and then be able to click it. You will need a function to call and an image:

root = Tk() # This is your window, if you want one to click on

#you need to define your image
image = your_image_here

def whatever_you_want_to_do():
    # and here you just put your code, this could be getting information about your button
    pass

b1 = Button(root, img=your_iamge, command=whatever_you_want_to_do) # This sets up your button

b1.pack()

root.mainloop() #your loop to run tkinter

Upvotes: 1

Related Questions