[英]Getting value from toplevel
I have a problem with getting value from Entry in toplevel.我在从顶级条目中获取价值时遇到问题。 my code:我的代码:
Wprowadz=Toplevel()
Wprowadz1=Entry(Wprowadz)
Wprowadz1.grid(row=0, column=0)
PrzyciskWprowadz=Button(Wprowadz, text="Wprowadź", width=30, height=2, command= lambda imie=Wprowadz1.get(), nazwisko="nazwisko", dimie=str("dimie"), klasa=str("klasa") : fun_sprowadzdosql(imie, nazwisko, dimie, klasa))
PrzyciskWprowadz.grid(row=1, column=0)
I want to get Wprowadz1 value to pass it to a function.我想获取 Wprowadz1 值以将其传递给函数。
You have to call the .get()
method after they click the button.单击按钮后,您必须调用.get()
方法。 You're calling it when defining the button.您在定义按钮时调用它。
Also, a word of advice: don't use lambda
, especially not with more than a single function inside.另外,一个忠告:不要使用lambda
,特别是不要使用多个函数。 While lambda
has its uses, code using lambda
can be hard to read, hard to write, and hard to debug for anything except for the simplest of cases.虽然lambda
有其用途,但使用lambda
代码可能难以阅读、难以编写,并且难以调试,除了最简单的情况。
PrzyciskWprowadz=Button(
Wprowadz, text="Wprowadź", width=30, height=2, command= callback
)
def callback():
imie=Wprowadz1.get()
fun_sprowadzdosql(imie, "nazwisko", "dimie", "klasa")
If you prefer to use lambda
, this will work:如果您更喜欢使用lambda
,这将起作用:
PrzyciskWprowadz=Button(
Wprowadz, text="Wprowadź", width=30, height=2,
command= lambda wprowadz1=Wprowadz1: fun_sprowadzdosql(wprowadz1.get(), "nazwisko", "dimie", "klasa"))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.