Python Forum
Newbie question with Tkinter Entry
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Newbie question with Tkinter Entry
#1
Hi
please someone can tell me why this code works
from tkinter import *
root=Tk()
root.title("teste ao programa")
#root.configure(background="black")
lopes=Entry(root,fg="red")
lopes.pack()
lopes.focus_set()
def ola():
    print(lopes.get())
    lopes.delete(0,END)    
b=Button(root,text="OK",width=6,command=ola)
b.pack()
mainloop()
and this code does not work

from tkinter import *
root=Tk()
root.title("teste ao programa")
#root.configure(background="black")
lopes=Entry(root,fg="red").grid(row=1,column=1)
#lopes.pack()
lopes.focus_set()
def ola():
    print(lopes.get())
    lopes.delete(0,END)    
b=Button(root,text="OK",width=6,command=ola).grid(row=1,column=0,sticky=W)
#b.pack()
mainloop()
Thnak you
Reply
#2
Separate the line for the grid statement and it will run the same as the other but using grid instead of the pack method..

from tkinter import *
root=Tk()
root.title("teste ao programa")
#root.configure(background="black")
lopes=Entry(root,fg="red")
lopes.grid(row=1,column=1)
#lopes.pack()
lopes.focus_set()
def ola():
    print(lopes.get())
    lopes.delete(0,END)
b=Button(root,text="OK",width=6,command=ola).grid(row=1,column=0,sticky=W)
#b.pack()
mainloop()
"Often stumped... But never defeated."
Reply
#3
from tkinter import *
root = Tk()
root.title("teste ao programa")
root.geometry('165x60')
lopes = Entry(root,fg="red").grid(row=0,column=0)
def ola():
    print(lopes.get())
    lopes.delete(0,END)    
b=Button(root,text="OK",width=6,command=ola).grid(row=1,column=0)
mainloop()
Don't forget row and coulmn start at index 0
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] question for a tkinter dialog box RobertAlvarez424 2 187 Aug-25-2021, 03:08 PM
Last Post: RobertAlvarez424
  .get() from generated Entry widgets in tkinter snakes 4 778 May-03-2021, 11:26 PM
Last Post: snakes
  Python tkinter question tablet Nick_tkinter 8 1,367 Mar-04-2021, 10:44 PM
Last Post: Larz60+
  tkinter slider question Nick_tkinter 1 587 Feb-22-2021, 01:31 PM
Last Post: deanhystad
  [Tkinter] Noob question:Using pyttsx3 with tkinter causes program to stop and close, any ideas? Osman_P 4 2,180 Nov-14-2020, 10:51 AM
Last Post: Osman_P
  Entry Validation in tkinter shahulvk 4 1,786 Oct-28-2020, 10:12 PM
Last Post: joe_momma
  question on tkinter canvas PhotoImage gr3yali3n 1 693 Sep-05-2020, 12:18 PM
Last Post: Larz60+
  [Tkinter] Getting Input from Tkinter Entry juliabrushett 6 15,041 May-30-2020, 03:29 PM
Last Post: Larz60+
  Converting Entry field value to integer in tkinter scratchmyhead 2 2,270 May-11-2020, 03:41 PM
Last Post: scratchmyhead
  [Tkinter] Tkinter adding entry values scratchmyhead 1 861 May-04-2020, 05:21 AM
Last Post: Yoriz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020