I have been working on a GUI-based program using Tkinter; it is coming along nicely and I am very pleased with the results.

I am at a point where I am trying to attempt a graphic manipulation of the GUI canvas. I have researched this but I am unsure what I should use:

Simply, at Run, the Canvas is built and rendered to the screen, a GIF image being displayed as the "background" of the canvas. This works great and I need no assistance with this. What I wish to do is to now (without any obvious change in the rendered window that the user would notice such as a flashing or jumping, opening\ closing of the window) is to "refresh" the canvas background image, hence displaying a new canvas-background GIF.

  • Run and build Tkinter canvas. Render first GIF as canvas background
  • Load 2nd, NEW GIF for new background
  • Load 3rd, NEW GIF for new background

What I have tried paints each GIF to the screen window (GUI) but only in the sense that the original then the to-be refreshed GIF are stacked upon one-another; The are combined and the GUI window is stretched to fit the two images. It should be only one GIF-- one after the other.

It is almost, in a sense, an animation, potentially, depending on how one handles the display time(s).

It is a very simple process, it seems. I just do not know the syntax\ code yet to allow this to happen.

Thank-you in advance,

sharky_machine

Now as I am thinking of it, you could put each image on a separate canvas and use each as a picture object, assigned to a dictionary, where the key is the card and the value the picture object (canvas and all). About 52 cards, that shouldn't be too much load on the old memory. If I find time, I might play with that!

Now as I am thinking of it, you could put each image on a separate canvas and use each as a picture object, assigned to a dictionary, where the key is the card and the value the picture object (canvas and all). About 52 cards, that shouldn't be too much load on the old memory. If I find time, I might play with that!

Hi:

Yes, this is actually what I did for the cards, in a sense, but I did not use a dictionary (I tried a dict and also a list-- the list worked better). The game is turning out very nice so far-- the GUI looks, IMO, very good. I am now working on the game logic which is fairly simple save for handling Aces-- 21 or 1? This will depend on what the player and the machine possess, respectively: I will have to check for Aces, check total values, and also watch for natural Blackjack. I am simplifying the rules a bit as some of the rules will be a bit much to interpret at this point in code it seems (splitting for example. I may work this in towards the end, but at this point there is no splitting allowed in the game)

The question I have about "refreshing" the canvas is not for the card GIFs but actually in the beginning when the canvas itself loads; I am essentially hoping to add a sort of "splash" screen intro to enhance the graphics, perhaps listing special rules of the game, etc. This may need a happen a few times before the actual game begins-- a simple animation. The entire canvas in the window must change seamlessly, not only particular elements within. Hope this makes sense.

sharky_machine

Something else you want to consider, the Python Image Library (PIL) has a Tkinter portion called ImageTk. I have had not much time to play with that.

Comments
Always Helpful and Inspiring to Coders.

I have been trying lift and lower with no verifiable or visible results (also been messing around with delete canvas-load canvas-- nothing). I am still getting two images (which are supposed to be seperately displayed) stacked on one-another, both displayed in one window. Perhaps I am placing lift and load in wrong areas of the code to facilitate its proper use? I do not get errors after compile\ run, just the resulting bi-level GIF window.

Example:

##----- test load one  -----##
# prep and create card images here
image00  = "TEST_ani.GIF"     
photo00  = PhotoImage(file=image00)
# canvas created here \/
# make canvas the size of image1/photo1
width1 = photo00.width()
height1 = photo00.height()
canvas2 = Canvas(width=width1, height=height1)
canvas2.pack()
# display photo1, x, y is center
x = (width1)/2.0
y = (height1)/2.0
canvas2.create_image(x, y, image=photo00)
[B]canvas2.lower(canvas2)[/B]
 
 
 
##----- test load two  -----##
# prep and create card images here
[B]canvas3.lift(canvas3)[/B]
image000  = "TEST_ani_1.GIF"     
photo000  = PhotoImage(file=image000)
# canvas created here \/
# make canvas the size of image1/photo1
width1 = photo000.width()
height1 = photo000.height()
canvas3 = Canvas(width=width1, height=height1)
canvas3.pack()
# display photo1, x, y is center
x = (width1)/2.0
y = (height1)/2.0
canvas3.create_image(x, y, image=photo000)
print photo0

This additional area of code is not necessary for the program to work properly-- it is potential eye-candy, but not vital. The GUI (minus this attempt) works wonderful. I am just attempting to punch up the visual appeal. I guess I need to get back to the game logic , and save the frilly, little extras for later :rolleyes: .

Thanks,
sharky_machine

I have been trying lift and lower with no verifiable or visible results (also been messing around with delete canvas-load canvas-- nothing). I am still getting two images (which are supposed to be seperately displayed) stacked on one-another, both displayed in one window. Perhaps I am placing lift and load in wrong areas of the code to facilitate its proper use? I do not get errors after compile\ run, just the resulting bi-level GIF window.

Example:

##----- test load one  -----##
# prep and create card images here
image00  = "TEST_ani.GIF"     
photo00  = PhotoImage(file=image00)
# canvas created here \/
# make canvas the size of image1/photo1
width1 = photo00.width()
height1 = photo00.height()
canvas2 = Canvas(width=width1, height=height1)
canvas2.pack()
# display photo1, x, y is center
x = (width1)/2.0
y = (height1)/2.0
canvas2.create_image(x, y, image=photo00)
[B]canvas2.lower(canvas2)[/B]
 
 
 
##----- test load two  -----##
# prep and create card images here
[B]canvas3.lift(canvas3)[/B]
image000  = "TEST_ani_1.GIF"     
photo000  = PhotoImage(file=image000)
# canvas created here \/
# make canvas the size of image1/photo1
width1 = photo000.width()
height1 = photo000.height()
canvas3 = Canvas(width=width1, height=height1)
canvas3.pack()
# display photo1, x, y is center
x = (width1)/2.0
y = (height1)/2.0
canvas3.create_image(x, y, image=photo000)
print photo0

This additional area of code is not necessary for the program to work properly-- it is potential eye-candy, but not vital. The GUI (minus this attempt) works wonderful. I am just attempting to punch up the visual appeal. I guess I need to get back to the game logic , and save the frilly, little extras for later :rolleyes: .

Thanks,
sharky_machine

This is solved: I will not go into the details at this time (if anyone needs\ wants to know the details I will be more than glad to try to explain it :) )

I arrived at this solution by researching Tkinter, hacking at the code and experimenting, and... with diligence; I believe diligence is the key to anything successful and especially coding due to its technical demands. It is so exciting to figure this out and actually have it working as planned. Thank-you to everyone who helped me. :cheesy:

Regards,
sharky_machine

This question has already been answered. Start a new discussion instead.