So, I'm attempting to make a GUI on python using tkinter for the first time, but I'm having trouble with the Pack()
attribute.
My code for the GUI thus far is as follows:
mainframe = tk.Tk()
mainframe.title("Hostname2IP")
mainframe.columnconfigure(1, weight=1)
mainframe.rowconfigure(1, weight=1)
SC= tk.scrolledtext.ScrolledText #shorten code a bit...
SC(master=mainframe, wrap=tk.WORD, width=5, height=15).grid(column=1, row=1, sticky=("NSEW"))
SC(master=mainframe, wrap=tk.WORD, width=5, height=15).grid(column=2, row=1, sticky=("NSEW"))
SC(master=mainframe, wrap=tk.WORD, width=5, height=15).grid(column=3, row=1, sticky=("NSEW"))
L1 = tk.Label(master=mainframe, text="Label1").grid(column=1, row=1, sticky="S")
L1 = tk.Label(master=mainframe, text="Label2").grid(column=2, row=1, sticky="S")
L1 = tk.Label(master=mainframe, text="Label3").grid(column=3, row=1, sticky="S")
tk.Button(master=mainframe, text="Open Targetslist", command=OpenTargetsButton).grid(column=1,row=3,sticky="W")
tk.Button(master=mainframe, text="Save Output", command=WriteOutButton).grid(column=2,row=3,sticky="E")
tk.Button(master=mainframe, text="Go", command=lambda: sequence(FilterList(file_path),\
GetIP_Mac(targethostlist),\
WriteOutput(Out_path))).\
grid(column=2, row=4, sticky="SE")
#bind key to a command
mainframe.bind('<Return>', lambda: sequence(FilterList(file_path),GetIP_Mac(targethostlist),WriteOutput(Out_path)))
mainframe.mainloop()
Running this displays:
As you can see, the labels are overlapping... And everything is uneven and messy too.
My issue right now is that I cannot apply Pack()
to L1
,L2
,L3
or any alike.
Doing: L1.Pack(side="bottom")
tells me " Theres no attribute 'pack' ". When I tried removing the grid(...)
config there, gives me another error:
_tkinter.TclError: cannot use geometry manager pack inside . which already has slaves managed by grid
So.. what am I doing wrong here?
EDIT: As said in the answers below, and in the last error, I had to use one geometry manager. I used grid
alone on the (only) window container and so it worked out fine. Pretty simple now actually.