Pack labels right next to entry box in tkinter python

user2633882 picture user2633882 · Aug 31, 2013 · Viewed 25.2k times · Source

I have a window that prompts users to enter the directory of their log files. However, my label seems to pack on top of my entrybox. Any idea on how to pack them side by side?

labelText=StringVar()

labelText.set("Enter directory of log files")

labelDir=Label(app,textvariable=labelText,height=4)

labelDir.pack()

directory=StringVar(None)

dirname=Entry(app,textvariable=directory,width=50)

dirname.pack()

Answer

user2555451 picture user2555451 · Aug 31, 2013

Yes, you need to set the side option to "left". See below:

from Tkinter import Tk, Label, Entry, StringVar

app = Tk()

labelText=StringVar()
labelText.set("Enter directory of log files")
labelDir=Label(app, textvariable=labelText, height=4)
labelDir.pack(side="left")

directory=StringVar(None)
dirname=Entry(app,textvariable=directory,width=50)
dirname.pack(side="left")

app.mainloop()

example:

sample