•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Python section within the Software Development category of DaniWeb, a massive community of 427,685 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,282 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Python advertiser: Programming Forums
Views: 1003 | Replies: 2 | Solved
![]() |
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)
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 9:03 pm.
I took the liberty to modify vegaseat's previous example code to show you how buttons would work:
from Tkinter import *
root = Tk()
root.title("Press Button!")
def show_image2():
canvas1.create_image(x, y, image=photo2)
def show_image3():
canvas1.create_image(x, y, image=photo3)
# pick three GIF image files you have in your working directory
# image1 is larger than image2 and image3
# create all three image objects now
image1 = "Red200x200.GIF"
photo1 = PhotoImage(file=image1)
image2 = "Green100x100.GIF"
photo2 = PhotoImage(file=image2)
image3 = "Blue100x100.GIF"
photo3 = PhotoImage(file=image3)
# make canvas the size of image1/photo1
width1 = photo1.width()
height1 = photo1.height()
canvas1 = Canvas(width=width1, height=height1)
canvas1.pack()
# display photo1, x, y is center
x = (width1)/2.0
y = (height1)/2.0
canvas1.create_image(x, y, image=photo1)
# create two buttons to display smaller images
btn1 = Button(root, text="Image2", command=show_image2)
btn1. pack()
btn2 = Button(root, text="Image3", command=show_image3)
btn2. pack()
root.mainloop() drink her pretty
![]() |
•
•
•
•
•
•
•
•
DaniWeb Python Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Passing value of string from one button click event to another (ASP.NET)
- Internet Explorer & Windows Explorer (desktop shortcuts) Won't Load! (Viruses, Spyware and other Nasties)
- Printing using Web Control Print button. (ASP.NET)
- Unable to open Internet Explorer, Windows Explorer, iTunes (Viruses, Spyware and other Nasties)
- Unwanted file in run menu (Windows NT / 2000 / XP / 2003)
Other Threads in the Python Forum
- Previous Thread: Keybindings and Image Display
- Next Thread: multiplication of dimensional analysis



Linear Mode