一组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已激活。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
在reducer中迭代自定义可写组件时出现java问题   属性文件中属性的java命名约定   任务链关闭的java Executor服务   java从Eclipse中的字段生成多个构造函数   java通过继承读取Json   java在不知道密钥的情况下解析json   java camel cxf如何在电子邮件中发送soap请求响应   java程序似乎跳过了if语句的一部分,在移回正确位置之前先移到else语句   测试简单的Java加密/解密inputFileName不存在   java从Jenkins REST API获取所有作业的所有构建的构建细节   java基本包装器和静态“类型”类对象   在WebSphere8.5上部署java代码   java对象相等(对象引用“=”)   java MongoDB整型字段到枚举的转换   每次我重新导入gradle时,IntelliJ都会不断重置Java设置   类型使用键或索引从Java中的数据类型检索值   在Java的列表接口中需要listIterator()和iterator()是什么?