Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # U08_Ex16_ModifyEvent_Loop2.py
- #
- # Author: Jaden Krekow
- # Course: Coding for OOP
- # Section : A3
- # Date: 19 Jan 2018
- # IDE: PyCharm Community Edition
- #
- # Assignment Info
- # Exercise: 16
- # Source: Python Programming
- # Chapter: 8
- # Program Description
- # Modified program to add a textbox wherever you click
- #
- # Algorithm (pseudocode)
- #
- # Modified Program
- from graphics import *
- def main():
- win = GraphWin('Click and type', 500, 500)
- while True:
- key = win.checkKey()
- if key == 'q':
- break
- if key:
- handleKey(key, win)
- pt = win.checkMouse()
- if pt:
- handleClick(pt, win)
- def handleKey(k, win):
- if k == 'r':
- win.setBackground('pink')
- elif k == 'w':
- win.setBackground('white')
- elif k == 'g':
- win.setBackground('lightgray')
- elif k == 'b':
- win.setBackground('lightblue')
- def handleClick(pt, win):
- entry = Entry(pt, 10)
- entry.draw(win)
- while True:
- key = win.getKey()
- if key == 'Return':
- break
- typed = entry.getText()
- entry.undraw()
- Text(pt, typed).draw(win)
- main()
Add Comment
Please, Sign In to add comment