Use the <img> Tag Inside the <button> Tag to Embed Image in the HTML Button. This <img> tag is used to embed an image on an HTML page.
The image buttons in the HTML document can be created by using the type attribute of an <input> element. Image buttons also perform the same function as submit buttons, but the only difference between them is that you can keep the image of your choice as a button.
Copy your image file within the Res/drawable/ directory of your project. While in XML simply go into the graphic representation (for simplicity) of your XML file and click on your ImageButton widget that you added, go to its properties sheet and click on the [...] in the src: field. Simply navigate to your image file.
The default button in HTML can be changed to an image using CSS. The required button is selected using the respective CSS selector. The background property can then be set to include a background image and change the image type as required. The border of the button can also be removed to show only the image itself.
I expect the same output for both of the scripts below.
But I don't get the image on the button when I execute Script 1. However, Script 2 works well.
Script 1
from Tkinter import * class fe: def __init__(self,master): self.b=Button(master,justify = LEFT) photo=PhotoImage(file="mine32.gif") self.b.config(image=photo,width="10",height="10") self.b.pack(side=LEFT) root = Tk() front_end=fe(root) root.mainloop()
Script 2
from Tkinter import * root=Tk() b=Button(root,justify = LEFT) photo=PhotoImage(file="mine32.gif") b.config(image=photo,width="10",height="10") b.pack(side=LEFT) root.mainloop()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With