| | |
Refreshing a Tkinter Canvas Multiple Times:
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
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.
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
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
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!
May 'the Google' be with you!
•
•
•
•
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!
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
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:
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
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
•
•
•
•
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
) 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
![]() |
Similar Threads
- Mysterious boot up issue, computer freezes at random times during bootup, erratic (Windows NT / 2000 / XP)
- Various log-in problems (Web Browsers)
Other Threads in the Python Forum
- Previous Thread: Fix Tkinter Widget Location
- Next Thread: Creating a Python ANSII game (dos)
| Thread Tools | Search this Thread |
Tag cloud for Python
ansi assignment avogadro backend beginner binary bluetooth character cmd code customdialog cx-freeze data decimals dictionary drive dynamic error examples excel exe file float format ftp function gnu graphics gui heads homework http ideas import input java leftmouse line linux list lists logging loop module mouse number numbers output parsing path pointer port prime program programming progressbar projects push py2exe pygame pyqt python random recursion recursive refresh schedule screensaverloopinactive script scrolledtext sqlite ssh statistics stdout string strings sudokusolver sum table terminal text thread threading time tkinter tlapse tricks tuple tutorial ubuntu unicode update urllib urllib2 variable wikipedia windows write wxpython xlib






