Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. class Application(Frame):
  2.  
  3. def __init__(root,master):
  4. Frame.__init__(root,master)
  5. root.grid()
  6. root.create_widgets()
  7.  
  8.  
  9.  
  10. def calcCR(root):
  11. d1 = root.enter.get()
  12. d1 = float(d1)
  13. #root.answer.delete(0.0,END)
  14. a = 'The C/R Alpha is! %lf n' % (d1)
  15. root.answer.insert(0.0, a)
  16.  
  17.  
  18. def create_widgets(root):
  19. ### Generate Element List ###
  20. for i in range(len(elem)):
  21. Label(root, text=elem[i]).grid(row=i+1, column=0)
  22.  
  23. ### Generate entry boxes for element wt% ###
  24. for i in range(len(elem)):
  25. enter = Entry(root, width = 8)
  26. enter.grid(row = i+1,column=1)
  27. enter.insert(0,'0.00')
  28.  
  29. root.button = Button(root, text = 'Calculate C/R', command = root.calcCR)
  30. root.button.grid(row=11, column=2, sticky = W, padx = 10)
  31.  
  32. root.answer = Text(root, width = 50, height = 12.5, wrap = WORD)
  33. root.answer.grid(row=1, column=2, rowspan = 10, sticky = W, padx = 10)
  34.  
  35.  
  36. root = Tk()
  37. root.title('C/R Calculator')
  38. app = Application(root)
  39. root.mainloop()
  40.  
  41. from tkinter import Tk, Frame, Label, Entry, Button
  42.  
  43. class App(Frame):
  44. def __init__(root, master):
  45. Frame.__init__(root, master)
  46. root.grid()
  47. root.create_widgets()
  48.  
  49. def get_values(root):
  50. return [float(entry.get()) for entry in root.entries]
  51.  
  52. def calc_CR(root):
  53. answer = sum(root.get_values()) #Replace with your own calculations
  54. root.answer.config(text=str(answer))
  55.  
  56. def create_widgets(root):
  57. root.entries = []
  58. for i in range(20):
  59. label = Label(root, text=str(i))
  60. label.grid(row=i, column=0)
  61.  
  62. entry = Entry(root, width=8)
  63. entry.grid(row=i, column=1)
  64. entry.insert(0, '0.00')
  65. root.entries.append(entry)
  66.  
  67. root.calc_button = Button(root, text='Calculate C/R', command=root.calc_CR)
  68. root.calc_button.grid(row=20, column=0)
  69.  
  70. root.answer = Label(root, text='0')
  71. root.answer.grid(row=20, column=1)
  72.  
  73. def run(root):
  74. root.mainloop()
  75.  
  76.  
  77.  
  78. root = Tk()
  79. root.title('C/R Calculator')
  80.  
  81. app = App(root)
  82. app.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement