0

i have this 2 custome modules and when i try to call module turtle i get an error message and i dont know what it means or better said i dont know where seems to be a problem. i think it should work just fine

this is the message i get:
AttrubuteError:'module' object has no attribute 'krog_s'

module codes:

risar:

from PyQt4.QtCore import *
from PyQt4.QtGui import *

app=QApplication([])
widget = QDialog()
widget.setWindowTitle("Janezovo zasilno platno")
widget.setLayout(QVBoxLayout())
widget.layout().setMargin(2)
widget.scene = QGraphicsScene(widget)
widget.scene.setBackgroundBrush(Qt.black)
widget.view = QGraphicsView(widget.scene, widget)
widget.view.setAlignment(Qt.AlignLeft | Qt.AlignTop)
widget.view.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding)
widget.view.setRenderHints(QPainter.Antialiasing | QPainter.SmoothPixmapTransform)
widget.layout().addWidget(widget.view)
widget.resize(800, 500)
widget.scene.setSceneRect(0, 0, widget.view.width(), widget.view.height())
widget.view.setSceneRect(0, 0, widget.view.width(), widget.view.height())
widget.show()
widget.raise_()
maxX = widget.view.width()
maxY = widget.view.height()

bela, crna, rdeca, zelena, modra, vijolicna, rumena, siva, rjava = barve = Qt.white, Qt.black, Qt.red, Qt.green, Qt.blue, Qt.magenta, Qt.yellow, Qt.gray, Qt.darkRed

barva = QColor

def obnovi():
    widget.scene.update()
    qApp.processEvents()

def cakajTipko():
    import msvcrt
    obnovi()
    msvcrt.getch()

def cakaj(t):
    import time
    obnovi()
    time.sleep(t)
    
def barvaOzadja(color):
    widget.scene.setBackgroundBrush(color)
    
def crta(x0, y0, x1, y1, color=bela, width=1):
    crta = widget.scene.addLine(0, 0, x1-x0, y1-y0, QPen(QBrush(color), width))
    crta.setPos(x0, y0)
    return crta

def tocka(x, y, color=bela):
    return widget.scene.addLine(x, y, x, y, QPen(QBrush(color), 1))

def elipsa(x, y, rx, ry, color=bela, width=1):
    elipsa = widget.scene.addEllipse(0, 0, rx, ry, QPen(QBrush(color), width))
    elipsa.setPos(x, y)
    return elipsa

def krog(x, y, r, color=bela, width=1):
    return elipsa(x, y, r, r, color, width)

def krog_s(x, y, r, color=bela, width=1):
    elipsa = widget.scene.addEllipse(-r, -r, 2*r, 2*r, QPen(QBrush(color), width))
    elipsa.setPos(x, y)
    return elipsa

def besedilo(x, y, txt, color=bela, size=20, font="Arial"):
    font = QFont(font)
    font.setPixelSize(size)
    txt = widget.scene.addText(txt, font)
    txt.setPos(x, y)
    txt.setDefaultTextColor(color)
    return txt

def slika(x, y, fname):
    pict = QPixmap(fname)
    pixmap = widget.scene.addPixmap(pict)
    pixmap.setPos(x, y)
    return pixmap

turtle

import risar
from math import pi, sin, cos, radians

class Turtle:
    def __init__(self):
        self.x, self.y = risar.maxX/2, risar.maxY/2
        self.angle = 0
        self.penActive = True

        self.pause = 0
        self.body = risar.krog_s(0, 0, 5, risar.zelena, 3)
        self.head = risar.krog_s(0, 0, 2, risar.zelena, 3)
        self.update()

    def show(self):
        self.body.show()
        self.head.show()

    def hide(self):
        self.body.hide()
        self.head.hide()

    def update(self):
        angle = radians(90 - self.angle)
        self.body.setPos(self.x, self.y)
        self.head.setPos(self.x+5*cos(angle), self.y-5*sin(angle))
        if self.pause:
            self.wait(self.pause)

    def setPause(self, s=-1):
        self.pause = s

    def noPause(self):
        self.setPause(0)

    def forward(self, l):
        angle = radians(90 - self.angle)
        nx, ny = self.x+l*cos(angle), self.y-l*sin(angle)
        nx, ny = max(0, nx), max(0, ny)
        nx, ny = min(nx, risar.maxX), min(ny, risar.maxY)
        if self.penActive:
            risar.crta(self.x, self.y, nx, ny)
        self.x, self.y = nx, ny
        self.update()

    def backward(self, l):
        self.forward(-l)

    def turn(self, angle):
        self.angle += angle
        self.update()

    def left(self):
        self.turn(-90)

    def right(self):
        self.turn(90)

    def penUp(self):
        self.penActive = False

    def penDown(self):
        self.penActive = True

    def fly(self, x, y, angle):
        self.x, self.y = x, y
        self.angle = angle
        self.update()

    def wait(self, s=0):
        if s>0:
            risar.cakaj(s)
        else:
            risar.cakajTipko()
2
Contributors
4
Replies
5
Views
5 Years
Discussion Span
Last Post by bomko
1

Another module may be hiding your module risar. Add print risar.__file__ after the 'import risar' in module turtle to see if it's importing from the expected file.

0

thank you very much it worked.

just one more thing. now that this works i tried a simple programm

import risar
from turtle import Turtle

t = Turtle()

def square(turtle, l):
    for i in range(4):
        turtle.forward(l)
        turtle.left(90)


for i in range(5):
    square(t, 150)
    t.turn(72)

and now it says that
Turtle object has no attribute 'Turn'

1

thank you very much it worked.

just one more thing. now that this works i tried a simple programm

import risar
from turtle import Turtle

t = Turtle()

def square(turtle, l):
    for i in range(4):
        turtle.forward(l)
        turtle.left(90)


for i in range(5):
    square(t, 150)
    t.turn(72)

and now it says that
Turtle object has no attribute 'Turn'

Again, beware that python has a builtin module 'turtle'; import turtle and print turtle.__file__ to see which one you are importing.

Edited by Gribouillis: n/a

0

oh so that was the main problem. didnt know about python having a built in module.

thank you very much

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.