一组Tkinter小部件,用于显示只读文本和代码。
tkreadonl的Python项目详细描述
一组Tkinter小部件,用于显示只读文本和代码。
开始
Tkreadonly只能从pypi安装:
pip install tkreadonly
只读文本
禁止所有用户编辑的ttk.Text小部件的扩展。
内置的ttk.text小部件没有“只读”模式。你可以 禁用小部件,但这也会禁用选择和其他鼠标 事件,并更改文本的颜色方案。
此小部件捕获并丢弃 文本小部件。这允许小部件的外观和行为类似于 ttk.Text其他方面的小部件。
参数
ReadOnlyText接受与基ttk.Text小部件相同的参数。
使用量
ReadOnlyText的用法与基^{tt1}的用法相同$ 小装置。
示例:
from Tkinter import * from tkreadonly import ReadOnlyText # Create the main Tk window root = Tk() # Create a main frame main_frame = Frame(root) main_frame.grid(column=0, row=0, sticky=(N, S, E, W)) # Put a ReadOnlyText widget in the main frame read_only = ReadOnlyText(main_frame) read_only.grid(column=0, row=0, sticky=(N, S, E, W)) # Add text to the end of the widget. read_only.insert(END, 'Hello world') # Run the main loop root.mainloop()
只读代码
一个复合小部件,允许您显示带行号注释的代码, 带有垂直滚动条。语法突出显示将自动 从文件名和/或文件内容猜测。
参数
style
The Pygments style sheet to use. Default is ^{tt8}$.
属性
filename
The filename currently being displayed. If you set this attribute, the path you provide will be loaded into the code window.
line
The current line of the file. The current line will be highlighted. If you set this attribute, any existing current line will be cleared and the new line highlighted.
方法
refresh()
Force a reload of the current file.
line_bind(sequence, func)
Bind the ^{tt13}$ event handler to the given event sequence on a line number. If an binding for the given sequence already exists, it will be overwritten.
Supports ^{tt14}$-^{tt15}$, and ^{tt16}$-^{tt17}$ sequences, with the ^{tt18}$, ^{tt19}$, and ^{tt20}$ modifiers.
When an event occurs, the handler will be invoked with a single argument - the event that occurred. This event object will have a ^{tt10}$ attribute that describes the line that generated the event.
name_bind(sequence, func)
Bind ^{tt13}$ event handler to the given event sequence on a token in the code. If an binding for the given sequence already exists, it will be overwritten.
Supports ^{tt14}$-^{tt15}$, and ^{tt16}$-^{tt17}$ sequences, with the ^{tt18}$, ^{tt19}$, and ^{tt20}$ modifiers.
When an event occurs, the handler will be invoked with a single argument - the event that occurred. This event object will have a ^{tt31}$ attribute that describes the token that generated the event.
使用量
示例:
from Tkinter import * import tkMessageBox from tkreadonly import ReadOnlyCode # Create the main Tk window root = Tk() # Create the main frame main_frame = Frame(root) main_frame.grid(column=0, row=0, sticky=(N, S, E, W)) # Create a ReadOnlyCode widget in the main frame read_only = ReadOnlyCode(main_frame) read_only.grid(column=0, row=0, sticky=(N, S, E, W)) # Show a particular file read_only.filename = '/path/to/file.py' # Highlight a particular line in the file read_only.line = 5 # Set up a handler for a double click on a line number def line_handler(event): tkMessageBox.showinfo(message='Click on line %s' % event.line) read_only.line_bind('<Double-1>', line_handler) # Set up a handler for a single click on a code variable def name_handler(event): tkMessageBox.showinfo(message='Click on token %s' % event.name) read_only.name_bind('<Button-1>', name_handler) # Run the main event loop root.mainloop()
ubuntu下的已知问题
ubuntu的python包从它的基础中省略了idlelib库 包装。如果你在ubuntu 13.04上使用python 2.7,你可以安装 idlelib运行:
$ sudo apt-get install idle-python2.7
对于其他版本的python和ubuntu,您需要将其调整为 适当的。
Windows下的问题
如果你在虚拟机里玩板球,你需要设置一个 环境变量,以便cricket可以找到tcl图形库:
$ set TCL_LIBRARY=c:\Python27\tcl\tcl8.5
您需要调整确切的路径以反映本地python安装。 将这一行放在activate.bat脚本中可能会有所帮助 为您的虚拟环境设置,以便在 Virtualenv已激活。