User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Python section within the Software Development category of DaniWeb, a massive community of 391,862 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 3,630 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:

Starting Python

Join Date: Oct 2004
Location: Mojave Desert
Posts: 2,394
Reputation: vegaseat will become famous soon enough vegaseat will become famous soon enough 
Rep Power: 9
Solved Threads: 172
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
Kickbutt Moderator

Solution Re: Starting Python

  #21  
Jul 14th, 2005
Just simple code to construct a toggle button, in this case we are using the venerable Tkinter for the GUI implementation.
  1. # make a toggle button with Tkinter
  2.  
  3. from Tkinter import *
  4.  
  5. toggleFlag = True
  6.  
  7. def entryColor():
  8. """toggle the entry color between white and red"""
  9. global toggleFlag
  10. if toggleFlag:
  11. e1.config(bg='red')
  12. toggleFlag = False
  13. else:
  14. e1.config(bg='white')
  15. toggleFlag = True
  16.  
  17. # create the root window
  18. root = Tk()
  19. # create a button, command runs the given function when button is clicked
  20. b1 = Button(root, text="Toggle Color", command=entryColor)
  21. # pack button into root window
  22. b1.pack(fill=BOTH, expand=1)
  23. # create an entry box to color
  24. e1 = Entry(root)
  25. e1.pack(fill=BOTH, expand=1)
  26.  
  27. # this allows the program to be an importable module and a runnable program
  28. if __name__ == "__main__":
  29. # start the event loop
  30. root.mainloop()
Click on "Toggle Plain Text" so you can highlight and copy the code to your editor.
Last edited by vegaseat : Mar 1st, 2007 at 3:13 pm. Reason: [code=python] tag
May 'the Google' be with you!
Reply With Quote  
All times are GMT -4. The time now is 6:44 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC