RSS Forums RSS

Graphics User Interface for Beginners

Please support our Python advertiser: Programming Forums
Reply
Posts: 2,111
Reputation: sneekula will become famous soon enough sneekula will become famous soon enough 
Solved Threads: 99
sneekula's Avatar
sneekula sneekula is offline Offline
Postaholic

Graphics User Interface for Beginners

  #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.
AddThis Social Bookmark Button
Reply With Quote  
Posts: 2,947
Reputation: vegaseat is a jewel in the rough vegaseat is a jewel in the rough vegaseat is a jewel in the rough 
Solved Threads: 254
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Graphics User Interface for Beginners

  #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  
Posts: 2,111
Reputation: sneekula will become famous soon enough sneekula will become famous soon enough 
Solved Threads: 99
sneekula's Avatar
sneekula sneekula is offline Offline
Postaholic

Re: Graphics User Interface for Beginners

  #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  
Posts: 1,066
Reputation: bumsfeld is an unknown quantity at this point 
Solved Threads: 47
bumsfeld's Avatar
bumsfeld bumsfeld is offline Offline
Veteran Poster

Re: Graphics User Interface for Beginners

  #4  
Nov 12th, 2006
Here are simple programs. The console version:
[php]# console sales tax program

while True:
price = float(raw_input("Enter purchase price: "))
# prevent division by zero error
if price != 0:
break
else:
print "price can not be zero!"

tax = float(raw_input("Enter sales tax paid: "))

percent = 100 * tax / price
print "You paid %0.3f%s sales tax" % (percent, '%')
[/php]Now the Tkinter GUI version:
[php]# Tkinter sales tax program

from Tkinter import *
import tkSimpleDialog

# the basic window
root = Tk()
# create label for result
label1 = Label(root)
# position the label in window
label1.grid(row=0, column=0)
# ask for needed data with dialog window
# the askfloat dialog window makes certain you entered floating point value
# and also prevents you from entering zero which would give divide by zero error
price = tkSimpleDialog.askfloat("Price", "Enter purchase price:", parent=root, minvalue=0.01)
tax = tkSimpleDialog.askfloat("Tax", "Enter sales tax paid:", parent=root)
percent = 100 * tax / price
result = "You paid %0.3f%s sales tax" % (percent, '%')
# display result string in label1
label1.config(text=result)
# event loop needed by GUI, checks for mouse and key events
root.mainloop()
[/php]
Reply With Quote  
Posts: 2,947
Reputation: vegaseat is a jewel in the rough vegaseat is a jewel in the rough vegaseat is a jewel in the rough 
Solved Threads: 254
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Graphics User Interface for Beginners

  #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  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Similar Threads
Other Threads in the Python Forum
Views: 2623 | Replies: 4 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 10:16 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC