关于 Tkinter 中的检索方法 [英] About retrieving method in Tkinter

查看:39
本文介绍了关于 Tkinter 中的检索方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我搜索从文本框中检索输入时,他们中的大多数人创建了一个方法 retrieve_input() 并在 Button 小部件命令中使用了该方法.retrieve_input() 方法特定于一个文本框.如果我有多个文本框并希望接收所有文本框的输入,是否必须为单个文本框创建每种方法?有没有办法创建一种通用方法来接收来自不同文本框的输入?还是我必须创建一个单独的类或模块(如果是这样怎么做?)

When I search for retrieving the input from textbox, most of them created a method retrieve_input() and used that method inside the Button widget command. The retrieve_input()method is specific for one textbox. If I have several textboxes and wants to receive the inputs from all of them, do I have to create each methods for individual textboxes? Is there a way to create a general method to receive the inputs from different textboxes? or do I have to create a separate class or modules (if so how to do it?)

我看到的例子之一是 如何从 Tkinter 文本框小部件获取输入?

推荐答案

您无需做任何特别的事情.文本小部件只是一个 python 对象,而 get 方法只是一个方法.您可以根据需要对任意数量的文本小部件对象调用该方法.

There's nothing special you need to do. The text widget is just a python object, and the get method is just a method. You can call that method on as many text widget objects as you want.

def retrieve_input():
    data1 = text1.get("1.0", "end-1c")
    data2 = text2.get("1.0", "end-1c")
    data3 = text3.get("1.0", "end-1c")
    ...

这篇关于关于 Tkinter 中的检索方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆