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
  Converting Entry field value to integer in tkinter scratchmyhead 2 95 May-11-2020, 03:41 PM
Last Post: scratchmyhead
  [Tkinter] Tkinter adding entry values scratchmyhead 1 135 May-04-2020, 05:21 AM
Last Post: Yoriz
  [Tkinter] Entry box not showing 2 decimal places Chuck_Norwich 3 126 Apr-24-2020, 05:28 PM
Last Post: deanhystad
  Always lowercase entry in tkinter ReturnName 8 292 Apr-18-2020, 09:41 AM
Last Post: PeroPuri
  Tkinter parameter question DPaul 2 160 Mar-14-2020, 09:35 AM
Last Post: DPaul
  Can't Get Entry Var in Tkinter OCaraDoBaixo 1 587 Feb-18-2020, 06:08 PM
Last Post: Larz60+
  [Tkinter] Getting Input from Tkinter Entry juliabrushett 4 11,060 Feb-13-2020, 12:12 AM
Last Post: reblark
  Transfer Toplevel window entry to root window entry with TKinter HBH 0 1,015 Jan-23-2020, 09:00 PM
Last Post: HBH
  [Tkinter] how to get the entry information using Entry.get() ? SamyPyth 2 980 Mar-18-2019, 05:36 PM
Last Post: woooee
  [Tkinter] Tkinter Entry widget and KeyPad intrgration chiragarya1992 0 2,139 Aug-11-2018, 01:09 AM
Last Post: chiragarya1992

Forum Jump:


Users browsing this thread: 1 Guest(s)