How to assign image to button

 

here we will be setting image to a button.

create a photo object and assign to image option while creating button.


below is the code for above screen-shot


# program

try:
from Tkinter import * # supports Python 2
except:
from tkinter import * # supports Python 3

mw = Tk()
mw.title(
"AETies : Automation Expert Technologies")
mw.geometry(
'400x100+50+50')
lbl = Label(mw
, text="below are two buttons with different images", pady=5, fg='blue').pack()
pic = PhotoImage(
file="./bg_2.png")
btn = Button(mw
, image=pic, highlightcolor='red', command=mw.destroy, padx=20,width=5, height=2)
btn.pack()
pic_1=PhotoImage(
file="./favicon.ico")
btn = Button(mw
, image=pic_1, highlightcolor='red',padx=5, command=mw.destroy)
btn.pack()

mw.mainloop()





Comments

My photo
Techno Xpresss
Bangalore, Karnataka, India