Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9146233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:42:05+00:00 2026-06-17T10:42:05+00:00

I wanted to ask a clever question about using Canvas as a container, but

  • 0

I wanted to ask a clever question about using Canvas as a container, but writing my example code I stumbled over something weird. Here is the code so far:

import Tkinter as tk

class CCanvas(tk.Canvas):

    def __init__(self,master,*args,**kwargs):
        super(CCanvas,self).__init__(master=master,*args,**kwargs)


if __name__ == '__main__':
    root= tk.Tk()
    cc = CCanvas(root)
    cc.pack()
    root.mainloop()

Now this code should not do much. The class CCanvas just inherits from Canvas, doesn’t implement anything, just calls the constructor of the super-class. I don’t see any reason for this not to work.
Yet, when I run this, I get the following error:

super(CCanvas,self).__init__(master=master,*args,**kwargs)
TypeError: must be type, not classobj

Can anyone explain this behavior to me and maybe tell me how to fix it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T10:42:07+00:00Added an answer on June 17, 2026 at 10:42 am

    The problem here is that TkInter classes (in 2.x) are old-style classes. The differences are described in detail in the Data Model documentation, but you don’t need to know the details for this; all you need to know is that you can’t use super (and how to work around that by explicitly calling __init__). And, as Steven Rumbalski points out, super() fails with error: TypeError “argument 1 must be type, not classobj” explains why you get this error message when the base class you’re trying to super to is on old-style class.

    This isn’t mentioned in the documentation, and it’s not really obvious unless you go looking for it, but if you know how to distinguish the two, it’s not that hard.

    As pointed out in a thread on python-list, this usually isn’t a problem, because if you need new-style class behavior, you can always just do class CCanvas(tk.Canvas, object):.

    But there are a few things that doesn’t take care of, and one of them is the ability to super to the base class. Instead, you have to do things the old-fashioned way and refer to the base class explicitly by name (which also means you have to pass self explicitly):

    def __init__(self,master,*args,**kwargs):
        TkInter.Canvas.__init__(self, master=master, *args, **kwargs)
    

    (Of course another solution is to migrate to Python 3 already, where there are no old-style classes…)

    (For the sake of completeness, it is possible to fake 90% of super with old-style classes, and there were some recipes floating around back in the early 2.x days… but you don’t want to do that.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wanted to ask about using selector from a variable first I have: function
I wanted to ask you a question about 301 URL redirection. So, I have
I wanted to ask about the best way to write this JQUERY code. I
Just wanted to ask you about the drawbacks (I mean memory or reponse time)
The question I always wanted to ask and was afraid to, actually - what
I wanted to ask about Forward Declarations in C. How generally they work. For
Just wanted to ask if there is any advantage for either using mouse click
I wanted to ask the SO community about this problem in my project. I
I wanted to ask about winApi 32 custom icons creation. When I define icon
I wanted to ask about the pros cons of my the following OOP style.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.