Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I get this error:

Traceback (most recent call last):
  File "bin/mybrowser", line 32, in <module>
    import mybrowser
  File "/home/shaunyo/mybrowser/mybrowser/__init__.py", line 14, in <module>
    from mybrowser import MybrowserWindow
  File "/home/shaunyo/mybrowser/mybrowser/MybrowserWindow.py", line 32
    def on_refreshbutton_clicked(self, widget):
                                          ^
IndentationError: unindent does not match any outer indentation level

This is my code:

    self.refreshbutton = self.builder.get_object("refreshbutton")

    def on_refreshbutton_clicked(self, widget):
    print "refresh"

Does anyone know what's wrong?

share|improve this question
    
I have updated my answer. –  AgentCool Aug 31 '13 at 5:42
    
Can you copy and paste your whole MybrowserWindow.py file into here and then provide the link in your question. I think that (after watching the video) that there is a problem with your indentation and that the code is no longer part of the MybrowserWindow class –  minerz029 Aug 31 '13 at 6:06
    
@minerz029 mysticpaste.com/view/hsk24ZfNo1?2 –  Shaun Aug 31 '13 at 6:27
    
See my new answer –  minerz029 Aug 31 '13 at 6:39

2 Answers 2

up vote 1 down vote accepted

I think you should have your code like

<TAB> self.refreshbutton = self.builder.get_object("refreshbutton")
<TAB> def on_refreshbutton_clicked(self, widget):
<TAB> print "refresh"

in your editor give a TAB everytime while entering in a new line.

Ok @Shaun

I think your code should look like

frank@FRANK-NATHE:~$ cat h.py
self.refreshbutton = self.builder.get_object("refreshbutton")
def on_refreshbutton_clicked(self, widget):
    print "refresh"

so don't use a tab for the 1st and 2nd lines and then use a tab for the 3rd line

If you still get confused then

enter image description here

share|improve this answer
    
Thanks for that, I gave it ago, and this what I got back: Traceback (most recent call last): File "bin/mybrowser", line 32, in <module> import mybrowser File "/home/shaunyo/mybrowser/mybrowser/__init__.py", line 14, in <module> from mybrowser import MybrowserWindow File "/home/shaunyo/mybrowser/mybrowser/MybrowserWindow.py", line 26 <TAB> self.refreshbutton = self.builder.get_object ("refreshbutton") ^ SyntaxError: invalid syntax –  Shaun Aug 31 '13 at 5:36
    
@Shaun You should press the 'Tab' key when you see <TAB> and the line which says print "refresh" should be indented an extra tab. If you're looking for a tutorial to get started with Python, I recommend the book A byte of Python –  minerz029 Aug 31 '13 at 5:38
    
@minerz029 Thanks for the edit. –  AgentCool Aug 31 '13 at 5:48
    
@rajagenupula Hello, I've tried that, good news is that the error has disappeared. The down side is that terminal isn't printing "Refresh" when I click the button "Refresh" in quickly. Any ideas? –  Shaun Aug 31 '13 at 5:49
    
@Shaun well that’s come under a new problem. I am not that much expert in the python.you better go with a new post. –  AgentCool Aug 31 '13 at 5:50

It looks like that the code is with the refresh function is not being run. Try indenting these highlighted lines an extra tab.

enter image description here

becomes

enter image description here

so that the code is run in the finish_initializing() function. Python is very particular with it's indentation

Note that the self.refreshbutton line is in line with the # Code for other... comment in the 2nd image

share|improve this answer
    
I've tried this, In terminal It's not generating "refresh". –  Shaun Aug 31 '13 at 6:45
    
@Shaun Can you try and indent those lines an extra tab each? –  minerz029 Aug 31 '13 at 6:46
    
Is there any way we can communicate about this, it would witch might make my understanding much better. –  Shaun Aug 31 '13 at 6:49
    
@Shaun see my updated answer with images –  minerz029 Aug 31 '13 at 6:52
    
Yes, I've did as you asked. I am still having the same problem. –  Shaun Aug 31 '13 at 7:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.