My tkinter entry box is printing .!entry instead of what is entered

穿精又带淫゛_ 提交于 2019-12-25 17:37:26

问题


from tkinter import *
def _name_():
              businessname=entry_bn
              print(businessname)
edit_bar=Tk()
name=Label(edit_bar,text="Name:").grid(row=0)
entry_bn=Entry(edit_bar)
entry_bn.grid(row=0,column=1)
submit=Button(edit_bar,text="Submit",command=_name_).grid(row=1,column=2)

Whenever i press my submit button, i get .!entry printed out, instead of what is entered into the entry box. Any ideas? Thank you


回答1:


Question: i get .!entry printed out, instead of what is entered into the Entry


Reference:

  • Tkinter.Entry.get-method

    Gets the current contents of the entry field. Returns the widget contents, as a string.


import tkinter as tk


class App(tk.Tk):
    def __init__(self):
        super().__init__()

        tk.Label(self, text="Name:").grid(row=0, column=0)
        self.entry = tk.Entry(self)
        self.entry.grid(row=0, column=1)

        btn = tk.Button(self, text="Submit", command=self.on_submit)
        btn.grid(row=2, column=0, columnspan=2, sticky='ew')

    def on_submit(self):
        print('Name: {}'.format(self.entry.get()))


if __name__ == "__main__":
    App().mainloop()


来源:https://stackoverflow.com/questions/59292903/my-tkinter-entry-box-is-printing-entry-instead-of-what-is-entered

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!