Reputation: 125
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
Upvotes: 1
Views: 61
Reputation: 46669
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()
Upvotes: 2