Python Tkinter:textfield输入命令

2024-06-07 07:29:36 发布

您现在位置:Python中文网/ 问答频道 /正文

如果用户在文本字段中按Enter键,我如何像FireonPress()那样触发fireonner()?在

from Tkinter import *

class Application(Frame):
    def FireonEnter(self):
        echo 'Enter pressed';

    def FireonPress(self):
        echo 'Button pressed';


    def createWidgets(self):
        self.Select = Button(self)
        self.Select["text"] = "OK",
        self.Select["width"] = "10",
        self.Select["command"] = self.FireonPress           
        self.Select.grid() 

        self.outputbox = Text(self) 
        self.outputbox["width"] = "20",
        self.outputbox["height"] = "1",           
        self.outputbox.grid() 

    [...]

Tags: 用户from文本echoselfdefbuttonwidth