Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image on a button

Tags:

People also ask

Can you put an image on a button?

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.

How do I put an image on a button in HTML?

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.

How will you add graphics to 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.

Can you put an image in a button CSS?

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()