I tried a lot to solve this, but the message "<bound method StringVar.get of <tkinter.StringVar object at 0x00000000024FB8E0>>" keeps being displayed, the .get() method wasn't working either for some reason, here is the code:
root.title("Testing this thing :D")
v = tk.StringVar()
label1 = tk.Label(root,text="Write your name").pack()
entrybox = tk.Entry(root,font= ("Arial 12"),textvariable=v).pack(expand=True)
def showmsg():
label = tk.Label(root, text = f"Hello {v.get}",font=("Arial 12")).pack()
button = tk.Button(root,font=("Arial 12"), command= showmsg(),text="Done").pack(fill= X)
root.mainloop()
CodePudding user response:
There are two problems in your code.
In Button, You give
command=showmsg()
Here you call this function This should becommand=showmsg
In function
showmsg
you wrotevar.get
This should bevar.get()
.
import tkinter as tk
root = tk.Tk()
root.title("Testing this thing :D")
v = tk.StringVar()
label1 = tk.Label(root,text="Write your name").pack()
entrybox = tk.Entry(root,font= ("Arial 12"),textvariable=v).pack(expand=True)
def showmsg():
label = tk.Label(root, text = f"Hello {v.get()}",font=("Arial 12")).pack()
button = tk.Button(root,font=("Arial 12"), command= showmsg,text="Done").pack(fill= tk.X)
root.mainloop()