Bottom Page

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
Quote
#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."
Quote
#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
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  [Tkinter] how to get the entry information using Entry.get() ? SamyPyth 2 507 Mar-18-2019, 05:36 PM
Last Post: woooee
  [Tkinter] Tkinter Entry widget and KeyPad intrgration chiragarya1992 0 991 Aug-11-2018, 01:09 AM
Last Post: chiragarya1992
  [Tkinter] Getting Input from Tkinter Entry juliabrushett 1 6,237 Jul-16-2018, 09:06 AM
Last Post: Larz60+
  [Tkinter] newbie with python and tkinter pat 8 1,741 Jun-26-2018, 07:43 PM
Last Post: pat
  [Tkinter] How to show and hide tkinter entry box when select yes from drop down Prince_Bhatia 1 1,484 Jun-12-2018, 08:05 AM
Last Post: Larz60+
  tkinter filedialog and pickle - custom icon question. kim07133 0 733 Jan-08-2018, 12:10 PM
Last Post: kim07133

Forum Jump:


Users browsing this thread: 1 Guest(s)