Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python button graphics.py

from graphics import *

WINDOW_WIDTH, WINDOW_HEIGHT = 200, 150

win = GraphWin("Simple Breakout", WINDOW_WIDTH, WINDOW_HEIGHT)

def buttons():
    left = Rectangle(Point(25, 55), Point(55, 85))  # points are ordered ll, ur
    right = Rectangle(Point(145, 55), Point(175, 85))
    quit = Rectangle(Point(85, 116), Point(115, 146))

    left.setFill("red")
    right.setFill("green")
    text = Text(Point(100, 133), "Exit")
    text.draw(win)

    left.draw(win)
    right.draw(win)
    quit.draw(win)

    return left, right, quit

def inside(point, rectangle):
    """ Is point inside rectangle? """

    ll = rectangle.getP1()  # assume p1 is ll (lower left)
    ur = rectangle.getP2()  # assume p2 is ur (upper right)

    return ll.getX() < point.getX() < ur.getX() and ll.getY() < point.getY() < ur.getY()

left, right, quit = buttons()

centerPoint = Point(WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2)
text = Text(centerPoint, "")
text.draw(win)

while True:
    clickPoint = win.getMouse()

    if clickPoint is None:  # so we can substitute checkMouse() for getMouse()
        text.setText("")
    elif inside(clickPoint, left):
        text.setText("left")
    elif inside(clickPoint, right):
        text.setText("right")
    elif inside(clickPoint, quit):
        break
    else:
        text.setText("")

win.close()
Comment

PREVIOUS NEXT
Code Example
Python :: setting python2 in the path for npm install 
Python :: one function in numpy array 
Python :: are there learning activities for django-debug-toolbar 
Python :: python typewriter effect 
Python :: find email address pytho 
Python :: re module python 
Python :: deletion in a binary search tree 
Python :: python int to scientific string 
Python :: Python program to count Even and Odd numbers using while loop in a List 
Python :: python get global variable by name 
Python :: python "urllib3" download and save pdf 
Python :: flatten list in python 
Python :: remove items from list while iterating python 
Python :: numpy subtract 
Python :: How to change application icon of pygame 
Python :: create smtp server python 
Python :: separate each characters by commas into a single characters separated by commas 
Python :: embeds discord.py 
Python :: python sum only numbers 
Python :: Python colon equals 
Python :: datatime add time in float 
Python :: add python to zsh wsl 
Python :: how to input a full array in one input in python 
Python :: Sort for Linked Lists python 
Python :: discord embed python 
Python :: Align axis labels in subplots 
Python :: return all values in a list python 
Python :: python selenium: does not wait until page is loaded after a click() command 
Python :: hh:mm to mins in python 
Python :: python dictionary map function 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =