Python HACk


SUBMITTED BY: Guest

DATE: Jan. 30, 2014, 5:22 p.m.

FORMAT: Text only

SIZE: 1.4 kB

HITS: 1208

  1. from tkinter import *
  2. def callback1(): # we got here when we pushed a button
  3. aa= e.get() # our text is just sitting in the text box so go 'get' it
  4. bb = e2.get() # e and e2 are the names of the boxes
  5. # the part after the dot is the method 'get'
  6. cc= e3.get()
  7. dd= e4.get()
  8. # aa= aa+ bb +cc+dd
  9. ## aa=int(aa)
  10. ## bb=int(bb)
  11. ## cc=int(cc)
  12. ## dd=int(dd)
  13. print (aa+bb+cc+dd)
  14. if aa =="cat":
  15. print ("You are correct - you must have E.S.P")
  16. else:
  17. print ("Keep guessing")
  18. master = Tk()
  19. e = Entry(master)
  20. e.pack()
  21. e.focus_set()
  22. e2 = Entry(master)
  23. e2.pack()
  24. e2.focus_set()
  25. e3 = Entry(master)
  26. e3.pack()
  27. e3.focus_set()
  28. e4 = Entry(master)
  29. e4.pack()
  30. e4.focus_set()
  31. b = Button(master, text="push here ", width=30, command=callback1) # goto callback1
  32. b.pack()
  33. # this widget is a Label
  34. # w is an instance of the Label object
  35. # an instance is created from a blueprint called a class
  36. w = Label(master, text=" This is a Label Widget ")
  37. w.pack()
  38. someVar="A Label widget was used to make this - this allows output (you cannot input anything here)"
  39. w2 = Label(master, text=someVar)
  40. w2.pack()
  41. mainloop()

comments powered by Disqus