我在python文件中有一个名为happy_histogram.py的代码:
__author__ = 'Bauer'
from graphics import GraphicsWindow
def drawHappyFace(canvas,x,y):
canvas.setColor("yellow")
canvas.setOutline("black")
#canvas.drawOval(100, 100, 30, 30)
canvas.drawOval(x, y, 30, 30)
canvas.setColor("black")
#canvas.drawOval(108, 110, 5, 5)
canvas.drawOval(x+8, y+10, 5, 5)
#canvas.drawOval(118, 110, 5, 5)
canvas.drawOval(x+18, y+10, 5, 5)
#canvas.drawLine(110, 122, 113, 125)
canvas.drawLine(x+10, y+22, x+13, y+25)
#canvas.drawLine(113, 125, 117, 125)
canvas.drawLine(x+13, y+25, x+17, y+25)
#canvas.drawLine(117, 125, 120, 122)
canvas.drawLine(x+17, y+25, x+20, y+22)
我需要将它导入我的pycharm程序才能使用这些函数。 我尝试了几种导入方法,但它们不起作用。 注意:pycharm项目和python文件位于同一文件夹中。
谢谢!
答案 0 :(得分:0)
不确定导入的含义,但缩进是错误的。而且我猜你在尝试从中导入GraphicsWindow的包名。
首次下载:
http://www.ezgraphics.org/uploads/Software/Download/ezgraphics-2.1.tar.gz
安装它:
pip install ezgraphics-2.1.tar.gz
然后试试这个:
__author__ = 'Bauer'
from ezgraphics import GraphicsWindow
def drawHappyFace(canvas,x,y):
canvas.setColor("yellow")
canvas.setOutline("black")
#canvas.drawOval(100, 100, 30, 30)
canvas.drawOval(x, y, 30, 30)
canvas.setColor("black")
#canvas.drawOval(108, 110, 5, 5)
canvas.drawOval(x+8, y+10, 5, 5)
#canvas.drawOval(118, 110, 5, 5)
canvas.drawOval(x+18, y+10, 5, 5)
#canvas.drawLine(110, 122, 113, 125)
canvas.drawLine(x+10, y+22, x+13, y+25)
#canvas.drawLine(113, 125, 117, 125)
canvas.drawLine(x+13, y+25, x+17, y+25)
#canvas.drawLine(117, 125, 120, 122)
canvas.drawLine(x+17, y+25, x+20, y+22)
drawHappyFace(GraphicsWindow().canvas(),400,400)
我猜你想要这样的东西:
__author__ = 'Bauer'
from ezgraphics import GraphicsWindow
import time
def drawHappyFace(canvas,x,y):
canvas.setHeight(200)
canvas.setWidth(200)
canvas.setColor("yellow")
canvas.setOutline("black")
canvas.drawOval(100, 100, 30, 30)
canvas.drawOval(x, y, 30, 30)
canvas.setColor("black")
canvas.drawOval(108, 110, 5, 5)
canvas.drawOval(x+8, y+10, 5, 5)
canvas.drawOval(118, 110, 5, 5)
canvas.drawOval(x+18, y+10, 5, 5)
canvas.drawLine(110, 122, 113, 125)
canvas.drawLine(x+10, y+22, x+13, y+25)
canvas.drawLine(113, 125, 117, 125)
canvas.drawLine(x+13, y+25, x+17, y+25)
canvas.drawLine(117, 125, 120, 122)
canvas.drawLine(x+17, y+25, x+20, y+22)
time.sleep(10000)
drawHappyFace(GraphicsWindow().canvas(),10,10)