Guest User

Untitled

a guest
Feb 19th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. # U08_Ex16_ModifyEvent_Loop2.py
  2. #
  3. # Author: Jaden Krekow
  4. # Course: Coding for OOP
  5. # Section : A3
  6. # Date: 19 Jan 2018
  7. # IDE: PyCharm Community Edition
  8. #
  9. # Assignment Info
  10. # Exercise: 16
  11. # Source: Python Programming
  12. # Chapter: 8
  13. # Program Description
  14. # Modified program to add a textbox wherever you click
  15. #
  16. # Algorithm (pseudocode)
  17. #
  18. # Modified Program
  19.  
  20. from graphics import *
  21.  
  22.  
  23. def main():
  24. win = GraphWin('Click and type', 500, 500)
  25. while True:
  26. key = win.checkKey()
  27. if key == 'q':
  28. break
  29. if key:
  30. handleKey(key, win)
  31. pt = win.checkMouse()
  32. if pt:
  33. handleClick(pt, win)
  34.  
  35.  
  36. def handleKey(k, win):
  37. if k == 'r':
  38. win.setBackground('pink')
  39. elif k == 'w':
  40. win.setBackground('white')
  41. elif k == 'g':
  42. win.setBackground('lightgray')
  43. elif k == 'b':
  44. win.setBackground('lightblue')
  45.  
  46.  
  47. def handleClick(pt, win):
  48. entry = Entry(pt, 10)
  49. entry.draw(win)
  50. while True:
  51. key = win.getKey()
  52. if key == 'Return':
  53. break
  54. typed = entry.getText()
  55. entry.undraw()
  56. Text(pt, typed).draw(win)
  57.  
  58. main()
Add Comment
Please, Sign In to add comment