Python Tkinter don';t创建按钮

Python Tkinter don';t创建按钮,python,tkinter,restructuredtext,Python,Tkinter,Restructuredtext,我正在用Tkinter开发重构文本编辑器。如果我运行下面的代码,我会得到缩进错误 from Tkinter import * from tkFileDialog import asksaveasfile as savefile class RSTkinter: def __init__(self): self.pencere_load() self.araclar() def pencere_load(self): pencer

我正在用Tkinter开发重构文本编辑器。如果我运行下面的代码,我会得到缩进错误

from Tkinter import *
from tkFileDialog import asksaveasfile as savefile

class RSTkinter:
    def __init__(self):
        self.pencere_load()
        self.araclar()

    def pencere_load(self):
        pencere.resizable(width=FALSE,height=FALSE)
        pencere.title("RSTkinter")

    def araclar(self):
        h1 = Button(text=u"Başlıklar",command=self.h1p)
        h1.place(rely=0.0)

        ..
        ..

        topic = Button(text="Topic",command=self.topic_p) # ..topic:: başlık \n\t içerik
        topic.place(rely=0.0,relx=0.63)

    def topic_p(self):
        topic = Toplevel()
        topic.title("RSTkinter - Not")
        topic.resizable(width=FALSE,height=FALSE)
        topic.geometry("200x140")

        topic_b_l = Label(topic,text=u"Topic başlığı: ")
        topic_b_l.place(relx=0.0,rely=0.0)

        self.topic_b = Text(topic)
        self.topic_b.place(relx=0.3,rely=0.0,width=130)

        topic_i_l = Label(topic,text=u"Topiç içeriği")
        topic_i_l.place(relx=0.0,rely=0.4)

        self.topic_i = Text(topic)
        self.topic_i.place(relx=0.3,rely=0.5,width=130)

        topic_y = Button(topic,text=u"Ekle",command=self.topic_yap)
        topic_y.place(relx=0.0,rely=0.2)

    def topic_yap(self):
        return self.metin.insert(END,"\n.. topic:: %s \n\t%s"%(self.topic_b.get(1.0,END)),self.topic_i.get(1.0,END)))

pencere = Tk()
rst = RSTkinter()

mainloop()
完全错误:

File "RSTkinter15.py", line 85
topic = Button(text="Topic",command=self.topic_p) #.. ^
IndentationError: unexpected indent

我该怎么做?

当我编写代码时,修复标识的最佳方法是转到问题上方的行,然后单击行的末尾,这样光标就在那里了。然后按enter键,在下一行为您输入正确的缩进。然后,我所做的就是一直按Delete按钮,将代码从下面移动到python shell为我制作的新缩进中。

如果错误消息告诉您有缩进错误,那么可以安全地假设这是真的。调试时的一个好的经验法则是始终相信编译器/解释器告诉您的内容


很可能是混合了空格和制表符——这是python的弱点之一。再次检查该行上的空格和制表符的组合是否与前一行相同

例如,在一段代码上与多人编程或使用多个编辑器(使用不同的默认设置)编程时,这通常是一个问题:一个使用(两倍/四倍)间距,另一个使用制表符。为了解决这个问题,我总是使用编辑器的内置替换函数(使用正则表达式):


“全部替换”非常有用,但要小心:您不想更改太多!按此顺序(否则您会将所有四倍间距更改为两个制表符)。

所有这些都与报告的缩进错误无关。@BryanOakley我重述了这个答案,现在是主题。您是否混合了制表符和空格?除此之外,大多数编辑器都可以选择将所有选项卡替换为空格,反之亦然。比手动操作快得多。
'    ' => '\t'   # search four spaces, replace with tab
'  ' => '\t'     # search two spaces, replace with tab