473,654 Members | 3,074 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using classes-TypeError: Unbound must be called as body instance...

4 New Member
TypeError: unbound method draw() must be called with Body instance as first argument (got Turtle instance instead)

I get that error when I attempt to run my program in python. I have to use the turtle module to draw the body of a car with body class. The class needs to have a init method and a draw method. The init method is supposed to determine fill color and draw is supposed to draw the object.

heres some of my code:
Expand|Select|Wrap|Line Numbers
  1. pen=turtle.Turtle()
  2. class Body(object):
  3.     def __init__(self,fillcolor=''):
  4.         self.fillcolor=fillcolor
  5.  
  6.     def draw(self,pen,size=80):
  7.         """draw the body of your car of given size using pen size is car length/2; fill it if fillcolor is provided"""
  8.  
  9.         if self.fillcolor:
  10.             pen.fillcolor(self.fillcolor)
  11.             pen.fill(True)
  12.         #draw the Body
  13.  
The rest of the code in the draw method is code that draws the body and it works when I separate it from the class in a different program. And it doesn't show but i have imported math and turtle.

Expand|Select|Wrap|Line Numbers
  1.         pen.down()
  2.         pen.forward(size*3/2)
  3.         pen.left(45)
  4.         pen.forward(size/2*math.sqrt(2))
  5.         pen.left(90)
  6.         pen.forward(size/2*math.sqrt(2))
  7.         pen.left(45)
  8.         pen.forward(size*3/2)
  9.         pen.right(45)
  10.         pen.forward(size/2*math.sqrt(2))
  11.         pen.left(45)
  12.         pen.forward(size*5/4)
  13.         pen.left(45)
  14.         pen.forward(size*1/4*math.sqrt(2))
  15.         pen.left(45)
  16.         pen.forward(size)
  17.         pen.left(45)
  18.         pen.forward(size*1/4*math.sqrt(2))
  19.         pen.left(45)
  20.         pen.forward(size*7/4)
  21.         pen.fill(False)                 # end filling
  22.  
Nov 26 '10 #1
2 2630
bvdet
2,851 Recognized Expert Moderator Specialist
You did not show how you called Body(). It should work if you instantiated Body() and called method draw() like this:
Expand|Select|Wrap|Line Numbers
  1. obj = Body()
  2. obj.draw(pen)
Nov 26 '10 #2
kevow123
4 New Member
thank you very much
Nov 26 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

12
7408
by: bissatch | last post by:
Hi, Generally if I re-use code, I use a function. If I need to use these functions over a number of pages I write the function to an include file where all pages have access. So when should I ever use PHP classes instead. I have learned how to put together PHP classes but never seen a reason to use them where I can simply use a function.
6
5435
by: Jake D | last post by:
I understand how to load a DLL in C++ and use functions from it, however I have a DLL which I did not create which has some classes in it. I can't seem to find out how to use the classes to make an object and then to be able to use methods of the object
1
1453
by: Donald Welker | last post by:
I'm building a web forms project and would like to provide consistent connection, data adapter, dataset objects, etc. across multiple ASPX pages. I'm having problems with trying to make these portable without breaking the IDE or Intellisense such that I can still get the benefits of the VS.Net objects without having the IDE replace most of the object's properties with each instantiation. I remember seeing a recent article in MSDN mag or...
0
834
by: Stu | last post by:
Hi, Ive been using classes as output from webservices which until now have worked well and have serialised into the xml i wanted. Now i want to have a structure of clients which have accounts which have securities So ive defined the following classes (See below) when I look a the xml when it gets to the <clientsaccounts> i dont see the full serialised definition
0
868
by: The Confessor | last post by:
I have a rather sprawling application-in-progress in Visual Basic .NET 2003, and I'm using very specific naming conventions to avoid confusion and make the function of my code as self-evident as possible. Below is an example, the name of a recently-declared Command Button: TabControl_Main_TabPage_MapEditor_TabControl_TileProperties_TabPage_Graph ic_Button_AddGraphic I'd love it if I could, in the interests of clarity, refer to that...
5
2807
by: Richard Gromstein | last post by:
Hello, I have an exercise that I need to finish very soon and I really need help understanding what to do and how exactly to do it. I am working on reading the chapter right now and working on it myself, but I have a feeling I won't get far. Please help me complete the exercise. I am posting what needs to be done and will be updating with pieces of code that I come up with. Thank you all for your attention. ...
3
1382
by: apedosmil8 | last post by:
I am having problems with using classes. I'm not sure why this program will not run. I have pointed out the problem. Thanks #include <iostream> #include <iomanip> #include <cmath> using namespace std; class Student
2
1338
by: =?Utf-8?B?d2lubGlu?= | last post by:
Hello 1) I agree that useing classes is the best way to use VB.net. The question is how do you write a VB program without using classes? 2) For my own edification where can I see an actual "full blown" VB .net program that doesn't use classes?
3
1355
by: Ramu528 | last post by:
Hi friends, I am populating a drop box from a table jos_qualifications. can anybody tell me how to populate a drop box using classes. something like $db->setQuery( $query ); this is my code which i have written without using classes ::::::::::::: $result = mysql_query( "SELECT category FROM jos_qualifications" ) or die("SELECT Error: ".mysql_error()); // start the select list echo '<select name="category"...
0
8290
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8489
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8594
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7307
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6161
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4149
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4294
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1916
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1596
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.