Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 26th, 2012  |  syntax: Python  |  size: 0.79 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. from Tkinter import *
  2. import math
  3.  
  4. def Square(radius):      
  5.   return math.pi * radius**2
  6.  
  7. def calculate_square():
  8.   radius = float(radius_entry.get())
  9.   try:
  10.     square = "%11.3f" % Square(radius)
  11.   except:
  12.     square = "?"
  13.   square_label.configure(text=square)
  14.  
  15. root = Tk()
  16. root.title("Площадь круга")
  17. frame = Frame(root)
  18. frame.pack()
  19. radius_entry = Entry(frame, width=10)
  20. radius_entry.grid(row=0, column=0)
  21. square_label = Label(frame, text="?")
  22. square_label.grid(row=0, column=1)
  23. eval_button = Button(frame, text="Calculate", width=10,
  24.                      command=calculate_square)
  25. eval_button.grid(row=1, column=0)
  26. exit_button = Button(frame, text="Exit", width=10,
  27.                      command=root.destroy)
  28. exit_button.grid(row=1, column=1)
  29. root.mainloop()