0

我想实时查看 Tkinter Entry 值。当我打字时,我看到 print 'downkey';。如果我输入 4 个字符,我看到的一个条目位于窗口底部 ok、ok、ok、ok 等。

from email . mime . multipart import MIMEMultipart
from email . mime . text import MIMEText
from Tkinter import *
from ttk import *

import ConfigParser
import smtplib

class Example ( Frame ):

    def __init__ ( self, parent ):

        self . ini ()
        Frame . __init__ ( self, parent )
        self . parent = parent
        self . initUI ()

    def initUI ( self ):

        self . parent . title ( "Quit button" )
        self . style = Style ()
        self . style . theme_use ( "default" )
        self . pack ( fill = BOTH, expand = 1 )
        inputfield = Entry ( self ) # I would like see this entry the app. window bottom in live, when i'm typewriter. If i key down/press call one function is class.
        inputfield . place ( x = 10, y = 10 )
        quitButton = Button ( self, text = "Quit", command = self . quit )
        quitButton . place ( x = 50, y = 50 )

def main ():

    root = Tk ()
    root . geometry ( "250x150+300+300" )
    app = Example ( root )
    root . mainloop ()

if __name__ == '__main__':

    main ()
4

1 回答 1

1

如果要在输入字段中键入后调用函数,则必须使用事件处理程序并将输入字段绑定到事件,例如按下返回和某些函数 xyz。这意味着按下回车后,可以调用函数 xyz。

要根据条目更新消息,您需要一个变量字符串作为条目的参数。

全局定义一个文本变量:

m=StringVar()

在 Eample 类中添加:

您可以将变量文本添加到输入字段

inputfield = Entry ( self,textvariable=m )

self.inputfield.bind('<Return>',self.xyz)  #to call xyz which you may want to define

并将文本变量添加到消息以更新它

message = Message(self,textvariable=m) #to update continuously the message which i hope you meant by "live"
于 2012-10-31T05:42:34.297 回答