[英]Python Entry box takes text input in multiple Entry box
Im making a GUI application where I have 4 Entry section and if I enter text in one Entry box all Entry box are taking data. 我正在制作一个GUI应用程序,其中有4个Entry部分,如果我在一个Entry框中输入文本,则所有Entry框都会获取数据。 How do I code such that only on clicking over Entry box it should take input respectively...
我该如何编码,以便仅在单击“输入”框时才应分别输入输入...
Code: 码:
from Tkinter import *
def time():
t1h=int(Ihr.get())
t1m=int(Imin.get())
t2h=int(Ohr.get())
t2m=int(Omin.get())
app = Tk()
app.title("VM")
app.geometry("150x210")
app.resizable(0,0)
note = Label(app, text="Clock IN Time :")
note.place(x=10, y=10)
Ihr = Entry(app,text="...")
Ihr.place(x=10, y=30,width="30")
Ihr.focus()
note = Label(app, text="::")
note.place(x=43, y=30)
Imin = Entry(app,text="...")
Imin.place(x=60, y=30,width="30")
note = Label(app, text="(hr)")
note.place(x=12, y=50)
note = Label(app, text="(min)")
note.place(x=58, y=50)
Ihr = Entry(app,text="...")
Imin = Entry(app,text="...")
I suspect the problem is on these two lines, in particular the text
keyword arguments. 我怀疑问题出在这两行,尤其是
text
关键字参数。 At first glance I don't see the behavior of text
documented anywhere , but I'm guessing they behave something like the textvariable
argument. 乍一看我没有看到的行为
text
记载 的任何地方 ,但我猜他们的行为有点像textvariable
说法。 Since they both point to the same "..." object, changing one Entry will change the other. 由于它们都指向同一个“ ...”对象,因此更改一个条目将更改另一个。
Don't use the text
argument to set the text of Entries. 不要使用
text
参数来设置Entries的文本。 Use the .insert
method instead. 请改用
.insert
方法。
Ihr = Entry(app)
Ihr.insert(0, "...")
Imin = Entry(app)
Imin.insert(0, "...")
Update: 更新:
Bryan Oakley confirms that the text
and textvariable
keyword arguments have the same effect. Bryan Oakley确认
text
和textvariable
关键字参数具有相同的效果。 Generally, you should not pass a string object to these arguments; 通常,您不应将字符串对象传递给这些参数。 a StringVar is most conventional.
StringVar是最常规的。 You may be interested in using StringVars here, since you can use their
.set
method to set the contents of the Entry objects, without having to use the arguably more complicated .insert
method. 您可能对这里使用StringVars感兴趣,因为您可以使用它们的
.set
方法来设置Entry对象的内容,而不必使用可能更复杂的.insert
方法。
Ihr_var = StringVar()
Ihr_var.set("...")
Ihr = Entry(app,text=Ihr_var)
Imin_var = StringVar()
Imin_var.set("...")
Imin = Entry(app,text=Imin_var)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.