[英]tkinter argument passing between two functions
from Tkinter import *
root=Tk()
x1=StringVar()
y=IntVar()
def hello(z):
print z
def temp():
root1=Tk()
x1.set("hello world")
Entry(root1,textvariable=x1).pack()
Button(root1,text="try me",command=(lambda :hello (x1.get()))).pack()
root1.mainloop()
Button(root,text="enter the new window",command=temp).pack()
root.mainloop()
iam new to tkinter.i am struck with argument passing between functions in tkinter 我是tkinter.i的新手,我在tkinter中的函数之间传递参数
in the above code when try me button is clicked i want the text entered in the entry box to be passed to the function but instead every time hello world is printing. 在上面的代码中单击“尝试我”按钮时,我希望在输入框中输入的文本传递给函数,而是每次打印hello world时。
please tell me way to get text from entry and that text must be passed on to the function thanks in advance 请告诉我从条目中获取文本的方法,并且必须事先将该文本传递给该函数
You are passing x1.get() to hello() that's why every time hello world
is printed. 您正在将x1.get()传递给hello(),这就是每次打印hello world
时的原因。 Instead of that, fetch the current Entry
text and pass it to hello(). 而不是那样,获取当前的Entry
文本并将其传递给hello()。 To fetch the current Entry
text, use the get
method of Entry Widget
要获取当前的Entry
文本,请使用Entry Widget
的get
方法
Modify your code as shown below: 修改您的代码,如下所示:
e = Entry(root1,textvariable=x1)
e.pack();
Button(root1,text="try me",command=(lambda :hello (e.get()))).pack()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.