0

I'm trying to put my 3 buttons inside the gray frame (labeled mainframe), even though I put the parent of the buttons as the frame.

import tkinter

class theUI():
    def __init__(self):
        self.root = tkinter.Tk()
        self.root.geometry("500x600")
        self.mainframe = tkinter.Frame(self.root, height=300, width=400, bg="gray").pack(side="left")
        tkinter.Button(master=self.mainframe, text="Rock").pack(side="left")
        tkinter.Button(master=self.mainframe, text="Paper").pack()
        tkinter.Button(master=self.mainframe, text="Scissors").pack(side="right")

        self.root.mainloop()


game = theUI()

I tried using pack and grid but they both gave me the same issue. I just started using tkinter so I'm still learning how the widgets work.

hopp hipp
  • 3
  • 1

1 Answers1

1

Note that self.mainframe is None because it is the result of .pack(...). So the buttons will be children of root window because their parent is None.

You need to separate the following line:

self.mainframe = tkinter.Frame(self.root, height=300, width=400, bg="gray").pack(side="left")

into two lines:

self.mainframe = tkinter.Frame(self.root, height=300, width=400, bg="gray")
self.mainframe.pack(side="left")
acw1668
  • 40,144
  • 5
  • 22
  • 34