Refreshing a Tkinter Canvas Multiple Times:

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Oct 2006
Posts: 2,564
Reputation: mattyd is an unknown quantity at this point 
Solved Threads: 1
Featured Poster
mattyd's Avatar
mattyd mattyd is offline Offline
Posting Maven

Refreshing a Tkinter Canvas Multiple Times:

 
0
  #1
Dec 10th, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,109
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 943
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Refreshing a Tkinter Canvas Multiple Times:

 
0
  #2
Dec 10th, 2006
You might nave to use the canvas lift() and lower() methods.
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,109
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 943
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Refreshing a Tkinter Canvas Multiple Times:

 
0
  #3
Dec 10th, 2006
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!
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,564
Reputation: mattyd is an unknown quantity at this point 
Solved Threads: 1
Featured Poster
mattyd's Avatar
mattyd mattyd is offline Offline
Posting Maven

Re: Refreshing a Tkinter Canvas Multiple Times:

 
0
  #4
Dec 10th, 2006
Originally Posted by vegaseat View Post
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
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,109
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 943
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Refreshing a Tkinter Canvas Multiple Times:

 
1
  #5
Dec 10th, 2006
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.
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,564
Reputation: mattyd is an unknown quantity at this point 
Solved Threads: 1
Featured Poster
mattyd's Avatar
mattyd mattyd is offline Offline
Posting Maven

Re: Refreshing a Tkinter Canvas Multiple Times:

 
0
  #6
Dec 11th, 2006
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)
canvas2.lower(canvas2)
 
 
 
##----- test load two  -----##
# prep and create card images here
canvas3.lift(canvas3)
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
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,564
Reputation: mattyd is an unknown quantity at this point 
Solved Threads: 1
Featured Poster
mattyd's Avatar
mattyd mattyd is offline Offline
Posting Maven

Re: Refreshing a Tkinter Canvas Multiple Times:

 
0
  #7
Dec 11th, 2006
Originally Posted by sharky_machine View Post
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)
canvas2.lower(canvas2)
 
 
 
##----- test load two  -----##
# prep and create card images here
canvas3.lift(canvas3)
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
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 608
Reputation: jrcagle is on a distinguished road 
Solved Threads: 150
jrcagle jrcagle is offline Offline
Practically a Master Poster

Re: Refreshing a Tkinter Canvas Multiple Times:

 
0
  #8
Dec 14th, 2006
I'd like to know...

Thanks,
Jeff
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Python Forum
Thread Tools Search this Thread



Tag cloud for Python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC