【问题标题】:how to change the entry's text when I click on the entry单击条目时如何更改条目的文本
【发布时间】:2020-07-10 05:20:53
【问题描述】:

我有这个入门类:

class my_entry(Entry):
def __init__(self,the_window):
    Entry.__init__(self,the_window)
    def changeText(Event):
        self["text"]="the new text"
        print("text changed")
    self.bind("<Button-1>", changeText)

现在当我点击它打印的条目时:text changed,但文本没有改变......

我有很多条目,所以我不能为每个条目使用set like:my_entry1.set("new text")

如何更改课程中条目的文本?

【问题讨论】:

  • 这能回答你的问题吗? Updating Text In Entry (Tkinter)。阅读The Tkinter Entry Widget
  • 正如我所说,我有很多条目,所以我希望为所有条目提供一个“功能”——或者从课堂上实现
  • “许多条目...一个“函数””&lt;entry&gt;.bind(... 回调正在与许多小部件一起使用,因为您从 @ 获得参考987654329@:阅读Events and Bindings
  • 答案可以在现成的文档中找到。阅读入口小部件的insertdelete 方法,以及event 对象在绑定函数中提供的内容。

标签: python python-3.x tkinter tkinter-entry python-class


【解决方案1】:

尝试这样做:

class my_entry(Entry):
    def __init__(self,the_window):
        Entry.__init__(self,the_window)
        def changeText(Event):
            self.delete(0,END)
            self.insert(0,"new text")
            print("text changed")
        self.bind("<Button-1>", changeText)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多