-1

I want a window that contains two frames. The top frame includes five labels for user input. The bottom frame includes two buttons. I got this result:

enter image description here

It is obvious that the button location is wrong. It seems to me that the button's grid does not work.

Here is my code:

frame1 = Frame(master).grid(row=0, sticky="ew")
frame2 = Frame(master).grid(row=1, sticky="ew")

Label(frame1, text="game name").grid(row=0, column=0)
Label(frame1, text="env").grid(row=1, column=0)
Label(frame1, text="event_source").grid(row=2, column=0)
Label(frame1, text="event_name").grid(row=3, column=0)
Label(frame1, text="game_id").grid(row=4, column=0)

e1 = Entry(frame1).grid(row=0, column=1)
e2 = Entry(frame1).grid(row=1, column=1)
e3 = Entry(frame1).grid(row=2, column=1)
e4 = Entry(frame1).grid(row=3, column=1)
e5 = Entry(frame1).grid(row=4, column=1)

Button(frame2, text='Quit', command=master.destroy).grid(row=0, column=0)
Button(frame2, text='Save', command=lambda: self.show_entry_fields(e1, e2, e3, e4, e5)).grid(row=0, column=3)
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Qingheyu
  • 3
  • 2

1 Answers1

0

You shouldn't be defining the grid details on the same line you define the frame.

frame1 = Frame(master).grid(row=0, sticky="ew")

returns None to frame1.

Instead write it as

frame1 = Frame(master)
frame1.grid(row=0, sticky="ew")

This goes for the rest of your labels and frames as well. Best practice to always define it separately, even if it sometimes looks like you can get away with it.

Emilio Garcia
  • 554
  • 1
  • 5
  • 20