2014-10-11 37 views
2

我試圖中心在使用Python 3.2中心矩形在新窗口

這裏新創建的窗口矩形是到目前爲止我的代碼:

from graphics import * 

def plotSquare(win, side): 
    rect=Rectangle(Point(side//2,side//2), Point(side,side)) 

    rect.setWidth(5) 
    rect.draw(win) 

def main(): 
    win=GraphWin("My Window", 500, 500) 
    win.setCoords(0, 0, 500, 500) 
    win.width=500 
    win.height=500 
    side=eval(input("What is the size of one side of the square (0<n<500): ")) 

    plotSquare(win, side) 

    win.getMouse() 
    win.close 

main() 

我可以使用哪些功能居中長方形?

回答

0

而不是定位矩形在邊/ 2,考慮到窗口的大小,所以矩形的左邊界將是500/2 - 邊/ 2。 矩形頂部的相同想法。

+0

你是一個拯救生命的人,非常感謝! – 2014-10-11 16:02:45