2012-10-30 75 views
0

我希望看到Tkinter Entry的值。当我打字时,我看到打印'downkey';.如果我输入4个字符,那么我可以看到在窗口中的底部正确,好的,好的,好的等等。Python实时输入Tkinter

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() 
+1

什么是t他之间的空间'。虽然它在语法上是正确的,但它是丑陋的......但无论如何 - 你的问题到底是什么? –

+0

@JonClements我打算开始修补答案,但我不知道你可以使用这样的点,所以也许我不是最好的人:) – RocketDonkey

+0

@RocketDonkey是的,也:'1 .__ str__ '不是有效的属性访问,它是一个无效的浮点数,但是(1).__ str__'或'1。 __str__'将起作用...好醇'Python –

回答

0

如果你想在输入字段中键入后调用一个函数,你将不得不使用事件处理程序,并输入字段绑定到事件就像回报媒体和一些功能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 

,并添加textvariable到的消息来更新它

message = Message(self,textvariable=m) #to update continuously the message which i hope you meant by "live" 
+0

inputfield = Entry(自身,textvariable = self。m) – sosdaniel

+0

inputfield。绑定('',self。xyz) – sosdaniel

+0

def xyz(self,varr):print varr – sosdaniel