1

i am new to using tkinter and python. I am trying to raise two frames simultaneously when a button is clicked. Here is my code:

from tkinter import *
import PIL.ImageTk

WIDTH = 1920
HEIGHT = 1080


def raise_frame(frame1, frame2):
    frame1.tkraise()
    frame2.tkraise()


# ********************************************************************************************************************
# ********************************************************************************************************************
# ********************************************************************************************************************
root = Tk()
root.geometry(f'{WIDTH}x{HEIGHT}')
root.title("Title")
backgroundImage = PIL.ImageTk.PhotoImage(file="Images/MainBackground.jpg")
DistancebackgroundImage = PIL.ImageTk.PhotoImage(file="Images/DistanceBackground.jpg")

canvas = Canvas(root, height=HEIGHT, width=WIDTH)
canvas.pack()

# Frames Begin ********************************************************************************************************
searchFrame = Frame(root, bg='#5f9cb8')
searchFrame.place(relwidth=1, relheight=0.05)

selectionFrame = Frame(root)
selectionFrame.place(rely=0.05, relwidth=1, relheight=1)
selectionFramebackground = Label(selectionFrame, image=backgroundImage)
selectionFramebackground.pack()

backFrame = Frame(root, bg='#000')
backFrame.place(relwidth=1, relheight=0.05)

distanceCalcFrame = Frame(root)
distanceCalcFrame.place(rely=0.05, relwidth=1, relheight=1)
distanceCalcFrameBackground = Label(distanceCalcFrame, image=DistancebackgroundImage)
distanceCalcFrameBackground.pack()
# Frames End *********************************************************************************************************

distanceCalcButton = Button(selectionFrame, text='Distance', bg='#000', command=lambda: raise_frame(distanceCalcFrame,
                                                                                                    backFrame))
distanceCalcButton.config(font=('helvetica', 20, 'bold'))
distanceCalcButton.place(relx='0.1', rely='0.1', relwidth='0.12', relheight='0.15')

raise_frame(selectionFrame)
raise_frame(searchFrame)
root.mainloop()
# ********************************************************************************************************************
# ********************************************************************************************************************
# ********************************************************************************************************************

I get this error :

Traceback (most recent call last):
  File "/ddd/computer/asd/Project/main.py", line 48, in <module>
    raise_frame(selectionFrame)
TypeError: raise_frame() missing 1 required positional argument: 'frame2'

Im basically asking how would i raise 2 or more frames at the same time. Thanks in advance

TINY T1ME
  • 115
  • 10
  • The error seems pretty clear: your function requires two arguments but you've passed in one. Have you tried passing in two arguments? – Bryan Oakley May 06 '20 at 03:58
  • You should combine `raise_frame(selectionFrame)` and `raise_frame(searchFrame)` into one `raise_frame(selectionFrame, searchFrame)`. – acw1668 May 06 '20 at 04:00
  • @BryanOakley Yes i have 2 arguments but for some reason i still get this error – TINY T1ME May 06 '20 at 04:08

1 Answers1

2

As the error said, the following two lines are invalid:

raise_frame(selectionFrame)
raise_frame(searchFrame)

Either combining the two lines into one:

raise_frame(selectionFrame, searchFrame)

or, to be flexible, you can modify raise_frame() to accept variable arguments:

def raise_frame(*frames):
    for frame in frames:
        frame.tkraise()
acw1668
  • 40,144
  • 5
  • 22
  • 34