943,670 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Unsolved
  • Views: 276
  • Python RSS
Jul 28th, 2009
0

GUI def destroying

Expand Post »
hey guys im trying to work this out for a school assignment, i cant get the destroy function to work whith the button i created, heres mycode see if you can look at it and tell me whas wrong
  
python Syntax (Toggle Plain Text)
  1. import Tkinter as tk
  2.  
  3. root = tk.Tk()
  4. root.title('background image')
  5.  
  6. def qwerty():
  7. self.destroy(button2)
  8.  
  9. #def qwerty():
  10. image1 = tk.PhotoImage(file="Black.gif")
  11. w = image1.width()
  12. h = image1.height()
  13. panel1.image = image1
  14. root.geometry("%dx%d+0+0" % (w, h))
  15.  
  16. panel1 = tk.Label(root, image=image1)
  17. panel1.pack(side='top', fill='both', expand='yes')
  18.  
  19. self.button2 = tk.Button(panel1, text='Click here to continue', command = qwerty)
  20. self.button2.pack(side='bottom')
  21.  
  22.  
  23.  
  24.  
  25. root.mainloop()
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
TubbyT is offline Offline
1 posts
since Jul 2009
Jul 29th, 2009
0

Re: GUI def destroying

The code you posted wouldn't even compile, let alone run.

Please be specific in the problem you are having.

I think the following is close to what you wanted, but it uses global variables which have their own problems:

Python Syntax (Toggle Plain Text)
  1. import Tkinter as tk
  2.  
  3. root = tk.Tk()
  4. root.title('background image')
  5.  
  6. def qwerty():
  7. button2.destroy()
  8.  
  9. #def qwerty():
  10. image1 = tk.PhotoImage(file="Black.gif")
  11.  
  12. w = image1.width()
  13. h = image1.height()
  14. #panel1.image = image1
  15. root.geometry("%dx%d+0+0" % (w, h))
  16.  
  17. panel1 = tk.Label(root, image=image1)
  18. panel1.pack(side='top', fill='both', expand='yes')
  19.  
  20. button2 = tk.Button(panel1, text='Click here to continue', command = qwerty)
  21. button2.pack(side='bottom')
  22.  
  23. root.mainloop()
Reputation Points: 344
Solved Threads: 116
Practically a Master Poster
Murtan is offline Offline
670 posts
since May 2008

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: Can I integrate Python and the web?
Next Thread in Python Forum Timeline: Cross-platform console manipulation





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


Follow us on Twitter


© 2011 DaniWeb® LLC