简体   繁体   English

使用tkinter在python中制作gui

[英]Using tkinter for making gui in python

I am trying to make a gui for a basic dbms project and while tkinter seems pretty easy for the most part i am unable to get how to use Entry to actually take the input and store it to use later (like an if condition or something) eg: 我正在尝试为基本的dbms项目制作gui,而在大多数情况下,tkinter似乎很容易,但是我无法获得如何使用Entry来实际获取输入并将其存储以供以后使用(如if条件或其他条件)例如:

root = Tk()
label = Label(root,text="Testing")
label.grid(row=0)
entry = Entry(root)
entry.grid(row=0,column=1)

Now what i want to do is use the value/word i just wrote in the entry field to say just print it out on for example the console. 现在我想做的就是使用我刚刚在输入字段中输入的值/单词说出来,例如在控制台上打印出来。

I thought we could just write 我以为我们可以写

print(entry)

but that justs prints some random decimal on the console, ideally id like to store the value in some variable (if its not possible to use just "entry") so i can also use it in if conditions etc 但这只是在控制台上打印一些随机的小数,理想情况下,id希望将值存储在某个变量中(如果不可能仅使用“ entry”),那么我也可以在条件等条件下使用它

I am using python 3 我正在使用python 3

you have to retrieve the value: 您必须检索值:

s=entry.get()
print(s)

you mean you want to show some data in entry? 您的意思是要在输入中显示一些数据?

you may just do it like this: 您可以这样做:

v = StringVar()
e = Entry(master, textvariable=v)
e.pack()

v.set("a default value")
s = e.get()

you can just set the value of "v", for example the Entry show " a default value" string. 您可以只设置“ v”的值,例如Entry show“默认值”字符串。 And you can get the value use "get" method. 您可以使用“ get”方法获取值。

By printing entry you are printing not what is in the entry, but the actual entry itself. 通过打印entry您打印的不是条目中的内容,而是实际的条目本身。 You need to use entry.get() to grab the contents of the entry. 您需要使用entry.get()来获取条目的内容。

print(entry.get())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM