<p>根据Bryan的建议,我能够解决Move_Up()和Move_Down()方法,如下所示。它可以在macosx上使用python3.1.3或2.6.6</p>
<pre><code>#swap this line with the line above it
def Move_Up():
text.config(state='normal')
# get text on current and previous lines
lineText = text.get("insert linestart", "insert lineend")
prevLineText = text.get("insert linestart -1 line", "insert -1 line lineend")
# delete the old lines
text.delete("insert linestart -1 line", "insert -1 line lineend")
text.delete("insert linestart", "insert lineend")
# insert lines in swapped order
text.insert("insert linestart -1 line", lineText)
text.insert("insert linestart", prevLineText)
#text.config(state='disabled')
#swap this line with the line below it
def Move_Down():
text.config(state='normal')
# get text on current and next lines
lineText = text.get("insert linestart", "insert lineend")
nextLineText = text.get("insert +1 line linestart", "insert +1 line lineend")
# delete text on current and next lines
text.delete("insert linestart", "insert lineend")
text.delete("insert +1 line linestart", "insert +1 line lineend")
# insert text in swapped order
text.insert("insert linestart", nextLineText)
text.insert("insert linestart + 1 line", lineText)
#text.config(state='disabled')
</code></pre>
<p><strong>编辑:</strong>请注意,如果只有一行文本,<code>Move_Up()</code>会将该文本附加到该行。如果只有一行,<code>Move_Down()</code>什么也不做。在</p>