What is the differences between tkinter in windows and Tkinter in theother platform?

H

Hidekazu IWAKI

Hi, I'm hidekazu.

I'm making a Tk application with python.
In the below code, the class App was inherited from Tkinter.Tk and the
__init__ method calls Tk's constructor with `super` method. In windows,
this code is valid (but, Tkinter -> tkinter).

Why does this code happen a type error in not windows platform?

thank you.

#--------------------------------------------------------
from Tkinter import *

class App(Tk):
def __init__(self):
super(Tk,self).__init__()

App().mainloop()

#Traceback (most recent call last):
# File "./app.py", line 16, in <module>
# App().mainloop()
# File "./app.py", line 7, in __init__
# super(Tk,self).__init__()
#TypeError: super() argument 1 must be type, not classobj

/////////////////////////////////////////////////
$B4d>k!!=(OB!J$$$o$-!!$R$G$+$:!K(B
e-mail: (e-mail address removed)
/////////////////////////////////////////////////
 
P

Peter Otten

Hidekazu said:
Hi, I'm hidekazu.

I'm making a Tk application with python.
In the below code, the class App was inherited from Tkinter.Tk and the
__init__ method calls Tk's constructor with `super` method. In windows,
this code is valid (but, Tkinter -> tkinter).

Why does this code happen a type error in not windows platform?

thank you.

#--------------------------------------------------------
from Tkinter import *

class App(Tk):
def __init__(self):
super(Tk,self).__init__()

App().mainloop()

#Traceback (most recent call last):
# File "./app.py", line 16, in <module>
# App().mainloop()
# File "./app.py", line 7, in __init__
# super(Tk,self).__init__()
#TypeError: super() argument 1 must be type, not classobj

In Python 2.x Tkinter uses classic classes (classes that do not inherit from
object), and super() can't handle these. In 3.x classic classes are gone,
and tkinter uses newstyle classes. So the behaviour changes from 2.x to 3.x,
but should be the same on all platforms.

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top