943,931 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Marked Solved
  • Views: 1801
  • Python RSS
Sep 22nd, 2006
0

Click event >> window appears?

Expand Post »
Hello again:

I seek assistance on what I believed would be an easy problem to solve, but, after much searching, I have not yet discovered a valid answer:

I have a canvas which consists of a background GIF upon which (when triggered) at least one new (smaller) GIF will appear, layered. I received help from someone here recently with that problem; it is set up to trigger the rendering of the smaller GIF upon the larger GIF background at this point-- I would like this image to appear as such upon a button click event (user input) This click event will act as the trigger for a 2D game I am writing. I do not need help with the game itself-- I am having trouble setting up the GUI, though.

I have been trying out many snippets and manipulating this code; I just need to learn how to bind a button such as "Play Now?" with the initialization of the game, the small GIF apearing on the larger, Canvas background. I need upon program call:

+ A display button and welcome message to render upon screen (have that already)

+ Bind this button input event (click) with the aforementioned large, GIF Canvas (Have this done, too) and when the button is clicked, a smaller GIF will appear upon the Canvas (layered on larger GIF), hence initializing the game from that point forward (all code beyond this initialization I have and is not relevant now)


Thank-you in advance for your kind, coding mentoring (it's getting put to good use) :cheesy:

reRanger

(** Using TKinter in DrPython IDE)
Last edited by tgreer; Sep 27th, 2006 at 10:03 pm.
Similar Threads
Reputation Points: 14
Solved Threads: 0
Newbie Poster
reRanger is offline Offline
23 posts
since Sep 2006
Sep 22nd, 2006
0

Re: Click event >> window appears?

I took the liberty to modify vegaseat's previous example code to show you how buttons would work:
Python Syntax (Toggle Plain Text)
  1. from Tkinter import *
  2.  
  3. root = Tk()
  4. root.title("Press Button!")
  5.  
  6. def show_image2():
  7. canvas1.create_image(x, y, image=photo2)
  8.  
  9. def show_image3():
  10. canvas1.create_image(x, y, image=photo3)
  11.  
  12.  
  13. # pick three GIF image files you have in your working directory
  14. # image1 is larger than image2 and image3
  15. # create all three image objects now
  16. image1 = "Red200x200.GIF"
  17. photo1 = PhotoImage(file=image1)
  18.  
  19. image2 = "Green100x100.GIF"
  20. photo2 = PhotoImage(file=image2)
  21.  
  22. image3 = "Blue100x100.GIF"
  23. photo3 = PhotoImage(file=image3)
  24.  
  25. # make canvas the size of image1/photo1
  26. width1 = photo1.width()
  27. height1 = photo1.height()
  28. canvas1 = Canvas(width=width1, height=height1)
  29. canvas1.pack()
  30.  
  31. # display photo1, x, y is center
  32. x = (width1)/2.0
  33. y = (height1)/2.0
  34. canvas1.create_image(x, y, image=photo1)
  35.  
  36. # create two buttons to display smaller images
  37. btn1 = Button(root, text="Image2", command=show_image2)
  38. btn1. pack()
  39. btn2 = Button(root, text="Image3", command=show_image3)
  40. btn2. pack()
  41.  
  42. root.mainloop()
Reputation Points: 625
Solved Threads: 211
Posting Virtuoso
Ene Uran is offline Offline
1,704 posts
since Aug 2005
Sep 22nd, 2006
0

Re: Click event >> window appears?

Thank-you for your reply-- this is very helpful. I am going to play around with this today and see what happens.

Appreciated much:cheesy:

reRanger
Last edited by tgreer; Sep 27th, 2006 at 10:02 pm.
Reputation Points: 14
Solved Threads: 0
Newbie Poster
reRanger is offline Offline
23 posts
since Sep 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: Keybindings and Image Display
Next Thread in Python Forum Timeline: multiplication of dimensional analysis





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC