Newbie question with Tkinter Entry - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: Newbie question with Tkinter Entry (/thread-21745.html) |
Newbie question with Tkinter Entry - mariolopes - Oct-12-2019 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 RE: Newbie question with Tkinter Entry - DT2000 - Oct-12-2019 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() RE: Newbie question with Tkinter Entry - Larz60+ - Oct-12-2019 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 |