English 中文(简体)
如何检查 tkinter 。 文本解析堆栈?
原标题:How to examine tkinter.Text undo stack?
Tk 文档谈到撤消堆栈, 但没有提到直接检查它的可能性 。 我希望在撤消堆栈用完后显示 Undo 命令为不活动 。 跟踪撤消和重做是我唯一的机会, 还是有办法询问堆栈是否是空的?
最佳回答
There is no way to explicitly examine the undo stack. However, you might be able to use the modified flag to serve a similar purpose. From the official tk documentation: The undo mechanism is also linked to the modified flag. This means that undoing or redoing changes can take a modified text widget back to the unmodified state or vice versa. The modified flag will be set automatically to the appropriate state. This automatic coupling does not work when the modified flag has been set by the user, until the flag has been reset again.
问题回答
To check whether or not you can undo/redo, you can use text.edit("canundo") and text.edit("canredo") This is from the tcl/tk documentation (since version 8.6): pathName edit canredo Returns a boolean true if redo is possible, i.e. when the redo stack is not empty. Otherwise returns false. pathName edit canundo Returns a boolean true if undo is possible, i.e. when the undo stack is not empty. Otherwise returns false. It s not built into tkinter as a function yet so we have to use an internal method: def edit(self, *args): """Internal method This method controls the undo mechanism and the modified flag. The exact behavior of the command depends on the option argument that follows the edit argument. The following forms of the command are currently supported: edit_modified, edit_redo, edit_reset, edit_separator and edit_undo """ return self.tk.call(self._w, edit , *args)




相关问题
How to make a Tkinter window jump to the front?

How do I get a Tkinter application to jump to the front? Currently, the window appears behind all my other windows and doesn t get focus. Is there some method I should be calling?

How to get the absolute path of a file using tkFileDialog?

I am using: file = tkFileDialog.askopenfile(parent=root, mode= rb , filetypes=[( Subrip Subtitle File , *.srt )], title= Choose a subtitle file ) to get a file object specified by the user. ...

How could I get a Frame with a scrollbar in Tkinter?

I d like to have a Frame, where the user could add as many textfields as needed by the application. The application starts with a textfield, and a button below that textfield. When the user presses ...

How to intercept WM_DELETE_WINDOW on OSX using Tkinter

I m trying to keep a Toplevel window from being closed in OSX by intercepting window manager WM_DELETE_WINDOW event. #!/usr/bin/env python from Tkinter import * def speak(): print "woof" ...

Linking Tcl/Tk to Python 2.5

I have an existing Python 2.4 and it is working properly with tkinter as I tested it using python import _tkinter import Tkinter Tkinter._test() Now, I have installed ...

How to bundle tkinter?

I am distributing an app that uses the Python/C API. I have all standard python modules in python31.zip which is basically an archive of the Lib folder in the python install directory. Here is the ...

How to play sound till the user hits a key?

First thought of implementing this using threads but python doesnt have a way for killing threads. I have read the other topic on killing threads. Is there any proper platform independent way of doing ...

热门标签