[英]Locating a graphic function (Python)
First off, thanks to the site and everybody on it. 首先,感谢网站和网站上的所有人。 I am taking my first python class and have come across this site many times when trouble-shooting coding problems.
我正在上我的第一个python类,并且在对代码问题进行故障排除时曾多次访问过此站点。 Thanks to everybody who have already helped me out a little thus far.
到目前为止,感谢所有已经帮助我的人。 But, I do have a problem I can't figure out:
但是,我确实有一个无法解决的问题:
I have to draw the "5" side of a die in a python graphics window. 我必须在python图形窗口中绘制模具的“ 5”面。 The catch is that I can't just draw them.
问题是我不能只画它们。 My "Dot" function has to be called 5 times to complete the graphic.
我的“点”功能必须调用5次才能完成图形。 I had trouble with the dot being placed on the rectangle, but the prof helped me out there.
我在将点放置在矩形上时遇到了麻烦,但是教授帮助了我。 I just can't seem to locate the same dot in different locations.
我似乎无法在不同位置找到相同的点。 Here is my code so far:
到目前为止,这是我的代码:
from graphics import*
def Dot(win):
# Draw a dot
center=Point(150,150)
circ=Circle(center,25)
circ.setFill('Black')
circ.draw(win)
def Dice():
#Build the dice (fill white, background green)
win=GraphWin('Shapes',500,500)
win.setBackground('Green')
rect=Rectangle(Point(100,100),Point(400,400))
rect.setFill('White')
rect.draw(win)
#Call dot 5 times with different locations:
Dot(win)
Dot(win)
Dot(win)
Dot(win)
Dot(win)
def main():
Dice()
main()
I have to call the "Dot" function 5 times. 我必须调用“点”函数5次。 However, I have tried to ".move(pt,pt), .locate, etc. I can't figure out how to take the "Dot" function and move it to a different location on the graphics window. Any help would be greatly appreciated.
但是,我尝试了“ .move(pt,pt)、. locate等。我不知道如何使用“点”功能并将其移动到图形窗口上的其他位置。任何帮助都是不胜感激。
Thanks. 谢谢。
I was finally able to get this one. 我终于能够得到这个。 I wasn't aware you could command after the window arguement.
我不知道你可以在窗口辩论之后命令。 So, the Dot(win, 350,150) etc. with the different coordinates worked well.
因此,具有不同坐标的Dot(win,350,150)等效果很好。 Thanks for the responses and help!
感谢您的答复和帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.