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!

Categories

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)
frame.pack()

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=StringVar()
v.set('win amount')

def func_1():
v.set(sum1)
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)

money_label

w = Label(bottomframe, textvariable=v)
w.pack(side=TOP)

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)

root.mainloop()

Sign In or Register to comment.