#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2005
    Location
    Gauteng, South Africa
    Posts
    405
    Rep Power
    161

    This code works on windows but not ubuntu


    Hi

    Whenever I use the following code in Ubuntu(newest version number 5.04) I get this error = app this constructor takes no arguments.
    It works on windows no problem. Can wrong indentation cause this problem? I copied the demo below out of the tutorial(I am trying to learn it), but typed it into Ubuntu(I use Gedit), so there is an outside change I messed up, although I retyped it twice.


    Code:
    from Tkinter import *
       class App:
          def __init__(self, master):
             frame = Frame(master)
             frame.pack()
             self.button = Button(frame, text="QUIT", fg="red",    command=frame.quit)
             self.button.pack(side=LEFT)
             self.hi_there = Button(frame, text="Hello", command=self.say_hi)
             self.hi_there.pack(side=LEFT)
          def say_hi(self):
             print "hi there, everyone!"
    root = Tk()
    app = App(root)
    root.mainloop()
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    394
    Rep Power
    52
    Hi!

    Well, your indentation is wrong, but then you should get another error message. Anyway, this one works on Ubuntu (and I hope on Windows too ):
    Code:
    from Tkinter import *
    
    class App:
        def __init__(self, master):
            frame = Frame(master)
            frame.pack()
            self.button = Button(frame, text="Quit", fg="red", command=frame.quit)
            self.button.pack(side=LEFT)
            self.hi_there = Button(frame, text="Hello", command=self.say_hi)
            self.hi_there.pack(side=LEFT)
        def say_hi(self):
            print "hi there, everyone!"
    
    root = Tk()
    app = App(root)
    root.mainloop()
    Regards, mawe

    Comments on this post

    • SimonGreenhill agrees
  4. #3
  5. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    155
    mawe, the only thing that you changed was the indentation problem. I don't see how that would make a difference on what system it will correctly work on.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    394
    Rep Power
    52
    Yegg, I never said that. The only error I found in the snippet was the indentation. I corrected it and tested the snippet (on Ubuntu). I also said that you should get another error message because of the wrong indentation. I don't have Windows, so I can't really test this (did you? ). And I still can't believe that it worked correctly on Windows with wrong indentation.
  8. #5
  9. (retired)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2003
    Location
    The Laboratory
    Posts
    10,101
    Rep Power
    0
    Yeah, it works fine on my copy on ubuntu (5.04 - Hoary Hedgehog). I cut'n'pasted Mawe's verison. Have you messed with the Python installation in any way (especially Tk)?

    --Simon
    Last edited by SimonGreenhill; June 16th, 2005 at 05:19 AM.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2004
    Posts
    461
    Rep Power
    25
    You have to make sure you have TK installed, It isn't installed by default on linux. I am not sure what urbonum or whatever it is called does for tk. But you have to usually install it yourself.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    394
    Rep Power
    52
    You're right, but that would also lead to another error message. I still don't understand why rigidninja gets the error message he posted, and why the snippet runs on Windows (with wrong indentation) at all.
  14. #8
  15. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    14
    The indentation is not wrong - it is just non-standard.

    You can have any number of spaces or tabs for indentation as long as you are consistent within a code block and at a given indentation level.

    I think you will find the reason some interpreters throw up errors is because they pass the code through a code checker (your using pythonwin?) before compiling it. The code checker picks up on things that can cause errors when modules are used by others (non-standard indentation, mixing tabs and spaces, using tabs instead of spaces) and are being stricter than the compiler actually needs to be.

    grim
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    394
    Rep Power
    52
    Originally Posted by Grim Archon
    You can have any number of spaces or tabs for indentation as long as you are consistent within a code block and at a given indentation level.
    Ok, but
    Code:
    from Tkinter import *
    
    class App:
    these two lines have to be at the same indentation level.
    And no, I don't use pythonwin, I run the code from the linux command line And I always get this error message:
    Originally Posted by Python
    ....class App:
    ....^
    SyntaxError: invalid syntax
    and not the one rigidninja posted.
  18. #10
  19. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    14
    Originally Posted by mawe
    Ok, but
    Code:
    from Tkinter import *
    
    class App:
    these two lines have to be at the same indentation level.
    True
    And no, I don't use pythonwin, I run the code from the linux command line And I always get this error message:

    and not the one rigidninja posted.
    I guess this is the tokenizer trying to makes sense of the bad spacing. A bit like a C compiler giving the wrong line number when a semi-colon is missing.
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    394
    Rep Power
    52
    Originally Posted by Grim Archon
    I guess this is the tokenizer trying to makes sense of the bad spacing.
    Right
    BTW: Do you have Windows? If so, could you test the original snippet (with the wrong indentation). I just want to know if it really works (not that I don't believe ridigninja, but ... )
  22. #12
  23. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2005
    Location
    Gauteng, South Africa
    Posts
    405
    Rep Power
    161
    I found the mistake yesterday!
    The constructor __init__ looked like it only have one _ on each side(I am new to python so I didnt realise this was wrong) Obviously the copy and paste worked in Windows, but when I retyped it in Gedit(cant copy and paste from the tutorial in ubuntu) I only typed one _ each side besause it looked like only one _.


    Thanks!

IMN logo majestic logo threadwatch logo seochat tools logo