how could i double a number when clicked on in the graphics window?... this is for graphics.py and a line separating the two sides in the graphics window and on each click on either side it must go up by 2 until 12? i can only think of using a loop?

for i in range(12):
	print i+2
from graphics import *
def tableTennisScorrer():
    w=250
    h=250
    win= Graphwin("table tennis", w, h)
    line = Line(Point(, 250), Point(0, 250))
    line.draw(win)

Recommended Answers

All 3 Replies

The title is somewhat misleading. You want to add 2.

This should give you an idea how to split the window into three parts. One could add to the left side score, the other to the right side score, and the third is for a click to exit.

#

from graphics import *

def main():
    win = GraphWin("My Score", 120, 100)
    rect_left = Rectangle(Point(0, 0), Point(50,100))
    rect_left.setFill('red')
    rect_left.draw(win)
    rect_right = Rectangle(Point(50, 0), Point(100,100))
    rect_right.setFill('green')
    rect_right.draw(win)
    while True:
        # get the x position of the mouse click
        click_posx = win.getMouse().getX()
        print( click_posx )  # test
        if click_posx < 51:
            print ( "left rect has been clicked")
        elif click_posx < 101:
            print ( "right rect has been clicked")
        else:
            break
    win.close()

main()

This should give you an idea how to split the window into three parts. One could add to the left side score, the other to the right side score, and the third is for a click to exit.

#

from graphics import *

def main():
    win = GraphWin("My Score", 120, 100)
    rect_left = Rectangle(Point(0, 0), Point(50,100))
    rect_left.setFill('red')
    rect_left.draw(win)
    rect_right = Rectangle(Point(50, 0), Point(100,100))
    rect_right.setFill('green')
    rect_right.draw(win)
    while True:
        # get the x position of the mouse click
        click_posx = win.getMouse().getX()
        print( click_posx )  # test
        if click_posx < 51:
            print ( "left rect has been clicked")
        elif click_posx < 101:
            print ( "right rect has been clicked")
        else:
            break
    win.close()

main()

how could i print nunbers on the actual grpahics window?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.