문제

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()
도움이 되었습니까?

해결책

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

다른 팁

You could always switch to using '.grid' instead.

With your code:

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.grid(row=1,column=1)

directory=StringVar(None)
dirname=Entry(app,textvariable=directory,width=50)
dirname.grid(row=1,column=2)

app.mainloop()

Code Running: https://gyazo.com/7c78e6f3d7c8fe9233f150072c44a0d1

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top