fork(1) download
  1. from tkinter import ttk
  2. from tkinter import *
  3. window = Tk()
  4. window.resizable(True, True)
  5. WinFrame = ttk.Frame(window)
  6. WinFrame.grid(sticky=NSEW)
  7. window.grid_columnconfigure(0, weight=1)
  8. window.grid_rowconfigure(0, weight=1)
  9. for col in range(5):
  10. WinFrame.grid_columnconfigure(col, weight=1)
  11. WinFrame.grid_rowconfigure(col, weight=1)
  12.  
  13. window.title('Calc')
  14. res = ""
  15. display = StringVar()
  16. calculation = ttk.Label(WinFrame, textvariable=display)
  17. calculation.grid(columnspan=4)
  18.  
  19.  
  20. def button_press(number):
  21. global res
  22. res += str(number)
  23. display.set(res)
  24.  
  25.  
  26. def result():
  27. global res
  28. try:
  29. display.set(str(eval(res)))
  30. except (ZeroDivisionError, SyntaxError):
  31. display.set("ERROR")
  32. finally:
  33. res = ''
  34.  
  35.  
  36. def clear():
  37. global res
  38. res = ''
  39. display.set(res)
  40.  
  41.  
  42. Button1 = ttk.Button(WinFrame, text='1', command=lambda: button_press(1))
  43. Button1.grid(row=1, column=0, sticky=NSEW)
  44. Button2 = ttk.Button(WinFrame, text='2', command=lambda: button_press(2))
  45. Button2.grid(row=1, column=1, sticky=NSEW)
  46. Button3 = ttk.Button(WinFrame, text='3', command=lambda: button_press(3))
  47. Button3.grid(row=1, column=2, sticky=NSEW)
  48. Button4 = ttk.Button(WinFrame, text='4', command=lambda: button_press(4))
  49. Button4.grid(row=2, column=0, sticky=NSEW)
  50. Button5 = ttk.Button(WinFrame, text='5', command=lambda: button_press(5))
  51. Button5.grid(row=2, column=1, sticky=NSEW)
  52. Button6 = ttk.Button(WinFrame, text='6', command=lambda: button_press(6))
  53. Button6.grid(row=2, column=2, sticky=NSEW)
  54. Button7 = ttk.Button(WinFrame, text='7', command=lambda: button_press(7))
  55. Button7.grid(row=3, column=0, sticky=NSEW)
  56. Button8 = ttk.Button(WinFrame, text='8', command=lambda: button_press(8))
  57. Button8.grid(row=3, column=1 ,sticky=NSEW)
  58. Button9 = ttk.Button(WinFrame, text='9', command=lambda: button_press(9))
  59. Button9.grid(row=3, column=2 ,sticky=NSEW)
  60. Button0 = ttk.Button(WinFrame, text='0', command=lambda: button_press(0))
  61. Button0.grid(row=4, column=1 ,sticky=NSEW)
  62. ButtonPlus = ttk.Button(WinFrame, text='+', command=lambda: button_press('+'))
  63. ButtonPlus.grid(row=1, column=3 ,sticky=NSEW)
  64. ButtonMinus = ttk.Button(WinFrame, text='-', command=lambda: button_press('-'))
  65. ButtonMinus.grid(row=2, column=3 ,sticky=NSEW)
  66. ButtonMultiply = ttk.Button(WinFrame, text='*', command=lambda: button_press('*'))
  67. ButtonMultiply.grid(row=3, column=3 ,sticky=NSEW)
  68. ButtonDivide = ttk.Button(WinFrame, text='/', command=lambda: button_press('/'))
  69. ButtonDivide.grid(row=4, column=3 ,sticky=NSEW)
  70. ButtonResult = ttk.Button(WinFrame, text='=', command=result)
  71. ButtonResult.grid(row=1, column=4, rowspan=4, sticky=NSEW)
  72. ButtonC = ttk.Button(WinFrame, text='C', command=clear)
  73. ButtonC.grid(row=4, column=0, sticky=NSEW)
  74. ButtonComma = ttk.Button(WinFrame, text='.', command=lambda: button_press('.'))
  75. ButtonComma.grid(row=4, column=2, sticky=NSEW)
  76.  
  77.  
  78. window.mainloop()
Runtime error #stdin #stdout #stderr 0.01s 8968KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "prog.py", line 1, in <module>
ImportError: No module named tkinter