Click here to Skip to main content
15,891,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
im trying to go another frame and go back to first frame with button.(like next page.)
i can go second frame easily but i cant go back to mainframe. i tried it with place_forget() and destroy(). but when i use them i cant see my mainframe.
which func i need to go back to mainframe named "messageWindow"
here is part of my code:
Python
messageWindow= Tk()
messageWindow.title("İstanbul")
messageWindow.geometry("400x600")
messageWindow.resizable(width=False,height=False)
frame1 = Frame(messageWindow, width =400, height=100, relief = tkinter.FLAT)
frame1.pack(side=TOP, expand= True, fill=BOTH)
frame2 = Frame(messageWindow, width =400, height=500, relief = tkinter.FLAT)
frame2.pack(side=TOP, expand= True, fill=BOTH)
def goSearchBarButton():
    searchbarFrame = Frame(messageWindow,width =400, height=600, relief = tkinter.FLAT)
    searchbarFrame.place(x=0,y=0)
    nframe1 = Frame(searchbarFrame, width =400, height=100, relief = tkinter.FLAT)
    nframe1.pack(side=TOP, expand= True, fill=BOTH)
    nframe2 = Frame(searchbarFrame, width =400, height=500, relief = tkinter.FLAT, background="black")
    nframe2.pack(side=TOP, expand= True, fill=BOTH)
    def goBack():
        nframe1.destroy()
        nframe2.destroy()  ## here is the part im having trouble with
    backIcon1 = PhotoImage(file="backIcon.png")
    backIconButton1 = Button(nframe1,image=backIcon1, command= goBack)
    backIconButton1.image= backIcon1
    backIconButton1.place(x=0, y=14)
searchbarIcon = PhotoImage(file="searchbar.png")
searchbarIconButton= Button(frame2, image = searchbarIcon, command= goSearchBarButton)
searchbarIconButton.place(x=40,y=30)backIcon=PhotoImage(file="backIcon.png")
backIconButton = Button(frame1, image=backIcon)
backIconButton.place(x=0,y=14)
messageWindow.mainloop()


What I have tried:

i tried it with place_forget() and destroy()
Posted
Comments
Richard MacCutchan 8-Dec-21 5:01am    
You may need to redraw the contents of the main window after you destroy the other frames. You should break your code into separate functions so you can call any part more than once.
yigit yılmaz 8-Dec-21 8:26am    
there is a lot of widgets in my main frame. do i really have to redraw all these widgets?
i tried to redraw main frame. but it didnt help
Richard MacCutchan 8-Dec-21 8:36am    
It is really a design issues. If you code everything in one long procedure then you will find it more and more difficult to fix problems. So fix your design now and you will be able to see where any corrections or improvements can be made.

See also How do I refresh tkinter window totally in python with a refresh button - Stack Overflow[^].

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900