首页 > 解决方案 > 蟒蛇 | tkinter:tkinter.END 做什么?

问题描述

通过一本书学习python,tkinter.END用在一块代码中,不做解释

import tkinter

def count(text, out_data):
    """ Update out_data with the total number of As, Ts, Cs, and Gs found in text.""" 

    data = text.get('0.0', **tkinter.END**)
    counts = {}
    for char in 'ATCG':
        counts[char] = data.count(char)
    out_data.set('Num As: {0} Num Ts: {1} Num Cs: {2} Num Gs: {3}'.format(
        counts['A'], counts['T'], counts['C'], counts['G']))
...

我在网上看过,我只遇到过它的例子,从来没有提到它的功能。help(tkinter)我在 shell 中尝试过,END = 'end'但它不是很有用。如果需要更多代码,请告诉我。不想发布整个代码,让您无缘无故地阅读更多内容。

标签: pythonpython-3.xuser-interfacetkinter

解决方案


它不“做”任何事情。它是一个常量,即字符串“end”。在这种情况下,它表示紧接在用户输入的最后一个字符之后的点。文本小部件上的函数get需要两个值:开始位置和结束位置。

注意:在 , 行text.get('0.0', tkinter.END)'0.0'是无效的(尽管,tkinter 欣然接受它,并将其视为'1.0')。文本索引的格式为line.character。行从 1 开始计数,字符从 0 开始。所以,第一个字符是'1.0',不是'0.0'


推荐阅读