Search code examples
pythonidetkintergeany

Mixing copied and typed code in geany


I was going through a Tkinter tutorial for python, and for one of the examples there was a lot of tedious typing involved, so I copied a large portion of it into my geany document. For some reason, Geany inserts a break before any copied code. This means that for the following bit of code:

def initUI(self):
    self.parent.title("Calculator")
-       
    ttk.Style().configure("TButton", padding=(0, 5, 0, 5), font='serif 10')

    self.columnconfigure(0, pad=3)

(break indicated by dash) The area that says self.columnconfigure returns a self not defined error, while the first line (self.parent.title) works fine. If I retype the lines by hand it all works fine, but I have no idea how to join the two cell blocks, and with around 75 boring lines of code I would really like to not type it all up. Does anyone know how to properly mix typed and pasted code in geany?


Solution

  • I don't know how to work with geany, but it appears the problem is that when you type you are using tabs for indentation, and when you paste you get spaces. This causes python to think those are two separate blocks of code.

    The best fix is to stop using tabs when you type in your code. Maybe there's a configuration setting for that. Your other option is to convert spaces to tabs on the pasted-in code. The vast, vast majority of python programmers use spaces. See Pep 8 - Style Guide for Python Code