Skip to content

Instantly share code, notes, and snippets.

@jaizon2000
Created March 9, 2019 19:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaizon2000/e09bca3a31c9934a6b9a18924bffa354 to your computer and use it in GitHub Desktop.
Save jaizon2000/e09bca3a31c9934a6b9a18924bffa354 to your computer and use it in GitHub Desktop.
from graphics import *
def main():
# make window
win = GraphWin("Fancy UI", 300, 400)
# Entry
Text(Point(100,100), "Name").draw(win)
entry = Entry(Point(200,100), 10)
entry.draw(win)
# Button
btn = Rectangle(Point(100,175), Point(200, 230))
btn.draw(win)
Text(Point(150, 200), "Greet").draw(win)
# Greeting
greeting = Text(Point(150,275), None)
greeting.draw(win)
while win.isOpen(): # While open
try:
pt = win.getMouse() # get point of mouse
except:
return
if (btn.p1.x < pt.x and pt.x < btn.p2.x and # if (x,y) of pt is less the (x,y) of the button points...
btn.p1.y < pt.y and pt.y < btn.p2.y):
greeting.setText("hello, " + entry.getText()) # Greet them, with the name entered in entry
else:
win.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment