Advertisement
rfmonk

fibGUI.py

Dec 16th, 2012
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.48 KB | None | 0 0
  1. #!/usr/bin/python
  2. # credit goes to antiloquax for all the fib scripts
  3. # see youtube https://www.youtube.com/watch?v=B4_tebsj2b0&list=PLDF973C3FA8572A0C
  4.  
  5. """I'm using python 3.2 for this tutorial. My GUI box looks and behaves different 1) there is no go! button 2) the title says <function fibonacci at 0xb7169...> its also unresponsive to entering via return key. I've checked for typos several times (this usually is my problem) But wouldn't it throw an exception? I don't see any errors. I'm writing in a ST2 editor then calling it from terminal like python3 /path/fibGUI.py any ideas? Thanks for the tut, very nice."""
  6.  
  7. #fibtk.py
  8. # a GUI version of the Fibonacci program, using recursion
  9.  
  10. import fib2
  11.  
  12. def start_fib():
  13.     num = input_box.get()
  14.     txt.delete(0.0, END)
  15.     try:
  16.         num = int(num)
  17.     except:
  18.         txt.insert(0.0, "I need an integer.")
  19.     txt.insert(0.0, str(fibonacci(num)))
  20.  
  21. def fibonacci(num):
  22.     if num <2:
  23.         return num
  24.     else:
  25.         num = fibonacci(num-1) + fibonacci(num-2)
  26.         return num
  27.  
  28. from tkinter import *
  29. root = Tk()
  30. root.title(fibonacci)
  31. root.geometry("300x100")
  32. app = Frame(root)
  33. app.grid()
  34.  
  35. input_lbl = Label(app, text= "Enter a number: ")
  36. input_lbl.grid(row = 0, column = 0, pady = 5 )
  37.  
  38. input_box = Entry(app, width = 10)
  39. input_box.grid(row = 0, column = 1, pady = 5)
  40.  
  41. bttn = Button(app, text = "go!")
  42. bttn["command"]= start_fib
  43. bttn.grid(row = 1, column = 0, pady = 5)
  44.  
  45. txt = Text(app, width = 15, height = 2)
  46. txt.grid(row=1, pady = 5)
  47.  
  48. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement