Graphics User Interface for Beginners

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Oct 2006
Posts: 2,279
Reputation: sneekula has a spectacular aura about sneekula has a spectacular aura about 
Solved Threads: 176
sneekula's Avatar
sneekula sneekula is offline Offline
Nearly a Posting Maven

Graphics User Interface for Beginners

 
0
  #1
Nov 10th, 2006
Which Graphics User Interface (GUI) would you recommend for a beginner? I have seen some examples of Tkinter, wxPython and GTK.
No one died when Clinton lied.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,028
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 932
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Graphics User Interface for Beginners

 
0
  #2
Nov 12th, 2006
As a beginner, start working with Tkinter to get a feeling what GUI programming is all about. Tkinter is already present in the normal Python installation. If you need fancier widgets later, download wxPython and experiment with that. PyGTK/GTK works best with Linux, the Windows version needs a lot of additional downloads and the installation process is cumbersome.
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,279
Reputation: sneekula has a spectacular aura about sneekula has a spectacular aura about 
Solved Threads: 176
sneekula's Avatar
sneekula sneekula is offline Offline
Nearly a Posting Maven

Re: Graphics User Interface for Beginners

 
0
  #3
Nov 12th, 2006
I will check Tkinter programming first. Any examples that show the difference between console and GUI programming?
No one died when Clinton lied.
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,221
Reputation: bumsfeld will become famous soon enough bumsfeld will become famous soon enough 
Solved Threads: 137
bumsfeld's Avatar
bumsfeld bumsfeld is offline Offline
Nearly a Posting Virtuoso

Re: Graphics User Interface for Beginners

 
0
  #4
Nov 12th, 2006
Here are simple programs. The console version:
  1. # console sales tax program
  2.  
  3. while True:
  4. price = float(raw_input("Enter purchase price: "))
  5. # prevent division by zero error
  6. if price != 0:
  7. break
  8. else:
  9. print "price can not be zero!"
  10.  
  11. tax = float(raw_input("Enter sales tax paid: "))
  12.  
  13. percent = 100 * tax / price
  14. print "You paid %0.3f%s sales tax" % (percent, '%')
Now the Tkinter GUI version:
  1. # Tkinter sales tax program
  2.  
  3. from Tkinter import *
  4. import tkSimpleDialog
  5.  
  6. # the basic window
  7. root = Tk()
  8. # create label for result
  9. label1 = Label(root)
  10. # position the label in window
  11. label1.grid(row=0, column=0)
  12. # ask for needed data with dialog window
  13. # the askfloat dialog window makes certain you entered floating point value
  14. # and also prevents you from entering zero which would give divide by zero error
  15. price = tkSimpleDialog.askfloat("Price", "Enter purchase price:", parent=root, minvalue=0.01)
  16. tax = tkSimpleDialog.askfloat("Tax", "Enter sales tax paid:", parent=root)
  17. percent = 100 * tax / price
  18. result = "You paid %0.3f%s sales tax" % (percent, '%')
  19. # display result string in label1
  20. label1.config(text=result)
  21. # event loop needed by GUI, checks for mouse and key events
  22. root.mainloop()
Last edited by vegaseat; Aug 13th, 2009 at 4:11 pm. Reason: newer code tags
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,028
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 932
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Graphics User Interface for Beginners

 
0
  #5
Nov 12th, 2006
Here is the Tkinter sales tax program without the dialog popups ...
  1. # a rather generic Tkinter GUI template for calculations
  2. # uses Entry() for data input and Button() to start calculation
  3.  
  4. from Tkinter import *
  5.  
  6. def calculate():
  7. try:
  8. # get the enter1 and enter2 values
  9. price = float(enter1.get())
  10. tax = float(enter2.get())
  11. # do the calculation
  12. percent = 100 * tax / price
  13. result = "You paid %0.3f%s sales tax" % (percent, '%')
  14. # display the result string
  15. label3.config(text=result)
  16. except ValueError:
  17. label3.config(text='Enter numeric values!')
  18. except ZeroDivisionError:
  19. label3.config(text='Price can not be zero!')
  20. enter1.focus_set()
  21.  
  22. root = Tk()
  23. # window geometry is width x height + x_offset + y_offset
  24. root.geometry("200x150+30+30")
  25.  
  26. # first entry with label
  27. label1 = Label(root, text='Enter purchase price:')
  28. label1.grid(row=0, column=0)
  29. enter1 = Entry(root, bg='yellow')
  30. enter1.grid(row=1, column=0)
  31.  
  32. # second entry with label
  33. label2 = Label(root, text='Enter sales tax paid:')
  34. label2.grid(row=2, column=0)
  35. enter2 = Entry(root, bg='yellow')
  36. enter2.grid(row=3, column=0)
  37.  
  38. # do the calculation by clicking the button
  39. btn1 = Button(root, text='Calculate Percent', command=calculate)
  40. btn1.grid(row=4, column=0)
  41.  
  42. # display the result in this label
  43. label3 = Label(root)
  44. label3.grid(row=5, column=0)
  45.  
  46. # start cursor in enter1
  47. enter1.focus()
  48. # value has been entered in enter1 now switch focus to enter2
  49. enter1.bind('<Return>', func=lambda e: enter2.focus_set())
  50.  
  51. root.mainloop()
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC