I believe that what is happening is that btn1 is being set to the first instance of Button, which is then packed (I prefer 'grid', BTW). Then btn1 is set to the second instance of Button, which is also packed. The reference to the first Button is then lost; your code has no way of accessing it, even though Tk continues to maintain a reference to it on its parent frame.
I don't know why pack.forget() doesn't fix that problem.
But if I understand your intent correctly, you want to switch out the button text and image, but not the button itself, yes?
One possibility is to use a textvariable for the Button rather than static text. It might also be possible to change the image on the fly.
See http://infohost.nmt.edu/tcc/help/pubs/tkinter.pdf for info on using textvariable.
Sorry for the partial solution; hope it helps.
Jeff
Jeff:
Thank-you for your reply.
Let me talk about the needed button function(s) again:
I am towards the tail-end of a GUI Python game build based on Blackjack. I am using Tkinter as my primary graphics module. The build is going very well and I believe it is almost complete (save for testing\ debugging) but I am at a point where I must finish the user input device (the button used to simply allow the player to "HIT" for another card).
This button will be visually, to the user, "one button", that is, they at all times (when the "HIT" button is made available to them to use) will see something like this:
[HIT]
*This is actually a pretty, damaged-metal, GIF-fronted button, not just text. No standard keyboard text will be displayed on this button or changed for any reason.
What does this button exactly do? Allows the player to request additional cards. How many cards? At this point (based on statistical studies I've conducted with decks of real playing cards to see how many cards on average allow one to reach "21" without going over) the player can request three (3) new cards via this button (after receiving two computer "dealt" cards) for a total of five (5) cards displayed for their hand. (I determined that, on average, 5 cards generally achieve "21" without going over "21")
I need this one button to allow a player to request a total of 3 new cards. This seems simple but I'm finding (possibly due to my coding design of logic and variables) this is more difficult than I first believed. I am very used to Visual Basic and I initially assumed I would activate buttons in a similar and easy way. Well, I am struggling with this and do not know why.
I figured as a work-around I could have the same
[HIT] with single function displayed 3-times without the player noticing-- no screen flash-- just a refresh of the GIF but with a different, seperate line of code imbedded in the background.
I just need to have one instance of this button allowing 3 "commands" which I cannot, it seems.
I'm not sure what I'm doing wrong. I've tried many things: so far, I only get 3 seperate [HIT] buttons displayed at once-- they all work great... but
I only need one to be displayed.
Thanks again for your help.
Regards,
sharky_machine