Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # credit goes to antiloquax for all the fib scripts
- # see youtube https://www.youtube.com/watch?v=B4_tebsj2b0&list=PLDF973C3FA8572A0C
- """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."""
- #fibtk.py
- # a GUI version of the Fibonacci program, using recursion
- import fib2
- def start_fib():
- num = input_box.get()
- txt.delete(0.0, END)
- try:
- num = int(num)
- except:
- txt.insert(0.0, "I need an integer.")
- txt.insert(0.0, str(fibonacci(num)))
- def fibonacci(num):
- if num <2:
- return num
- else:
- num = fibonacci(num-1) + fibonacci(num-2)
- return num
- from tkinter import *
- root = Tk()
- root.title(fibonacci)
- root.geometry("300x100")
- app = Frame(root)
- app.grid()
- input_lbl = Label(app, text= "Enter a number: ")
- input_lbl.grid(row = 0, column = 0, pady = 5 )
- input_box = Entry(app, width = 10)
- input_box.grid(row = 0, column = 1, pady = 5)
- bttn = Button(app, text = "go!")
- bttn["command"]= start_fib
- bttn.grid(row = 1, column = 0, pady = 5)
- txt = Text(app, width = 15, height = 2)
- txt.grid(row=1, pady = 5)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement