Changing the image on a button - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Changing the image on a button

nattylinuxnattylinux Posts: 4Member

Am trying to change 5 cards from the default card back image to front images by clicking the deal button but to no effect. Just need a little guidance. Thanks.

from Tkinter import *

import tkMessageBox

root = Tk()
frame = Frame(root)

topframe = Frame(root)
topframe.pack(side = TOP)

bottomframe = Frame(root)
bottomframe.pack( side = BOTTOM )

card_list = ('c_1_.gif','c_2_.gif','c_3_.gif','c_4_.gif','c_5_.gif')

ButtonImage1 = PhotoImage(file= 'card_back.gif')
ButtonImage2 = PhotoImage(file= 'card_back.gif')
ButtonImage3 = PhotoImage(file= 'card_back.gif')
ButtonImage4 = PhotoImage(file= 'card_back.gif')
ButtonImage5 = PhotoImage(file= 'card_back.gif')

num1 = 100
num2 = 5
sum1 = num1 - num2

v.set('win amount')

def func_1():
button_card_two = Button(topframe, image=ButtonImage2)
#button_card_two.pack( side = LEFT )

def deal():
ButtonImage1 = PhotoImage(file= card_list[0])
ButtonImage2 = PhotoImage(file= card_list[1])
ButtonImage3 = PhotoImage(file= card_list[2])
ButtonImage4 = PhotoImage(file= card_list[3])
ButtonImage5 = PhotoImage(file= card_list[4])

button_card_one = Button(topframe, image=ButtonImage1 )
button_card_one.pack( side = LEFT)

button_card_two = Button(topframe, image=ButtonImage2)
button_card_two.pack( side = LEFT )

button_card_three = Button(topframe, image=ButtonImage3)
button_card_three.pack( side = LEFT )

button_card_four = Button(topframe, image=ButtonImage4)
button_card_four.pack( side = LEFT)

button_card_five = Button(topframe,image=ButtonImage5)
button_card_five.pack( side = LEFT)


w = Label(bottomframe, textvariable=v)

Play_button1 = Button(bottomframe, text="DEAL", fg="black" , command = func_1)
Play_button1.pack(side = LEFT)

Play_button2 = Button(bottomframe, text="STAND", fg="black")
Play_button2.pack(side = LEFT)

Play_button3 = Button(bottomframe, text="EXIT", fg="black")
Play_button3.pack(side = LEFT)


Sign In or Register to comment.