使用grid()
您可以grid_columnconfigure()
在父项上使用Entry
import tkinter as tk
root = tk.Tk()
tk.Entry(root).grid(sticky='we')
root.grid_columnconfigure(0, weight=1)
root.mainloop()
使用pack()
你可以使用fill='x'
import tkinter as tk
root = tk.Tk()
tk.Entry(root).pack(fill='x')
root.mainloop()
顺便说一句:使用:
self.path = tk.Entry().grid()
您将的结果分配给grid()
,self.path
但grid()
始终返回None
。
如果需要,self.path
请执行以下操作:
self.path = tk.Entry()
self.path.grid()
如果您不需要,self.path
则可以执行以下操作:
tk.Entry().path.grid()