0

So in this code I am storing my input in var and when I want to print this var with the button you can't see the output in the console. But when I print it like print(input.get()) it works perfectly

 def button(text="Hello", width=20, height=20, x=20, y=200, bg="white", 
      command=0, font="Verdana 10 bold"):
      button = Button(frame, text=text, width=width, height=height,font=font, 
      command=command, bg=bg)
      button.place(x=x, y=y)



 def printer():
     print(var)
   
input = Entry(width=50)
input.place(x=20, y=220)
var = input.get()



button("Submit", 6, 2, 20, 240, command=printer)


window.mainloop()
  • 2
    why are you using ```input```,a built-in method, as a variable name – Yash Feb 07 '21 at 16:23
  • The command "button" seems to me quite strange. In general is `(master, text = 'About', command=self.about, width = 20).grid(row = 0, column = 1)`. But please, insert the full code. – Jonny_92 Feb 07 '21 at 16:26

1 Answers1

0

You are calling the .get() method on initialisation, so var holds an empty string since there is nothing in the input field.

Now, when you call print(input.get()) then the current value is fetched and printed, hence it works and the former doesn't.

astqx
  • 2,058
  • 1
  • 10
  • 21