0

I have been trying to place the label a,b inside frame 2.

import random
from  tkinter import *

root = Tk()

root.title("Rock Paper Scissor")

root.geometry("600x600")

# user choice frame
frame1 = Frame(root, height=200, bg="cyan")
frame1.pack(fill=X)
# frame1.pack_propagate(0) # stop frame from force fit

Button(frame1, text="ROCK").pack(side=TOP)
Button(frame1, text="PAPER").pack(side=TOP)
Button(frame1, text="SCISSOR").pack(side=TOP)

# score frame
frame2 = Frame(root, height=50,bg="orange").pack(fill=X)
a = Label(frame2, text="Your score")
b = Label(frame2, text="Computer score")
a.pack()
b.pack()

root.mainloop()

but whenever i run this code label a and b show below the frame 2.

martineau
  • 119,623
  • 25
  • 170
  • 301
Puneet56
  • 126
  • 1
  • 9

2 Answers2

2

This has been already answered here

Frame(root, height=50,bg="orange").pack(fill=X) does not return a frame, instead it returns None. So your frame2 is always None.

You should do the same as you did for the frame1.

frame2 = Frame(root, height=50, bg="orange")
frame2.pack(fill=X)
1

Try below code.

import random
from  tkinter import *

root = Tk()

root.title("Rock Paper Scissor")

root.geometry("600x600")

# user choice frame
frame1 = Frame(root, height=200, bg="cyan")
frame1.pack(fill=X)
# frame1.pack_propagate(0) # stop frame from force fit

Button(frame1, text="ROCK").pack(side=TOP)
Button(frame1, text="PAPER").pack(side=TOP)
Button(frame1, text="SCISSOR").pack(side=TOP)

# score frame
frame2 = Frame(root, height=50,bg="orange")
frame2.pack(fill=X)
a = Label(frame2, text="Your score")
b = Label(frame2, text="Computer score")
a.pack()
b.pack()
root.mainloop()
Seyon Seyon
  • 527
  • 4
  • 14