Python Forum
[Tkinter] Needs help to switch frame with functions - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: [Tkinter] Needs help to switch frame with functions (/thread-26680.html)



Needs help to switch frame with functions - scotesse - May-09-2020

Hello,
I am having some troubles with my code.
My problem is that I have defined a canvas with a button and I want that when I click on that button, I go to the frame which is define inside a fonction. I have been trying to do that but I didn't succeed. If you have an idea, it would be awesome.
Thanks a lot and have a nice day

Here is an example of the form of my code.
On that code, I want the button in def welcome to make the function TheOtherFunction runs and this function will make the ExampleFunctions runs.

from tkinter import Tk, Canvas, Button, Frame, PhotoImage, IntVar, Label, Radiobutton

def welcome() : 
    for c in window.winfo_children():
        c.pack_forget()
    canvample = Canvas(window, width=680, height=600, bg="#FFFFFF")
    picexample = PhotoImage(file = "example.png")
    gifsdict["example.png"] = picexample
    canvample.create_image(540, 340, image=picexample)
    Button(window, text='exammmple', command=TheOtherFunction(table, window)).place(x=100,y=190)
    txt1 = canvample.create_text(250,220,text="exammmplleee")
    canvample.pack()
    
def ExampleFunction(table, string1, int1, string2, window):
    for c in window.winfo_children():
        c.destroy()
    frameeee = Frame(window)
    def okay(ans):
        if ans ==0 : 
            i = i+5
            TheOtherFunction (table, window)
        if ans ==6 : 
            i = i-1
            TheOtherFunction (table, window)
    ans_choice = IntVar()
    ans_choice1 = Radiobutton(frame1, text="lalala", variable=ans_choice, value=0)
    ans_choice2 = Radiobutton(frame1, text="blablabla", variable=ans_choice, value=2)
    OkayButton = Button(frame1, text="Okay", command=lambda: okay(ans_choice.get()))
    ans_choice1.pack()
    ans_choice2.pack()
    OkayButton.pack()
    frameee.pack()

def TheOtherFunction(table, window):
    string1 = "mamma mia"
    int1 = 20
    string2 = "so funny"
    ExampleFunction(table, string1,int1, string2, window)
    endframe = Frame(window)
    if i <= -5:
        lno = Label(framefin, text="no")
        lno.pack()    
    framefin.pack

window = Tk()
window.geometry("680x600")
gifsdict={}
pagebienvenue()
window.mainloop()



RE: Needs help to switch frame with functions - Larz60+ - May-09-2020

you can do this using tkinter lift and lower. see: https://python-forum.io/Thread-Tkinter-Creating-a-restart-button-for-a-Pythagorean-Theorem-Program?pid=111150#pid111150


RE: Needs help to switch frame with functions - scotesse - May-10-2020

(May-09-2020, 10:44 PM)Larz60+ Wrote: you can do this using tkinter lift and lower. see: https://python-forum.io/Thread-Tkinter-Creating-a-restart-button-for-a-Pythagorean-Theorem-Program?pid=111150#pid111150

Hi, thanks for the hint. I have checked the thread you sent and lift and lower but I still don't really know how to do that...


RE: Needs help to switch frame with functions - Larz60+ - May-10-2020

I knew that you didn't know how to do it, that's why I presented an example.
did you try running the example to see how it works?
a few more examples: https://riptutorial.com/tkinter/example/22131/arranging-the-window-stack--the--lift-method-
https://riptutorial.com/tkinter/example/22131/arranging-the-window-stack--the--lift-method-

If windows occupy the same space, only lift is needed, as the lifted window will block the one underneath.


RE: Needs help to switch frame with functions - scotesse - May-10-2020

(May-10-2020, 10:32 AM)Larz60+ Wrote: I knew that you didn't know how to do it, that's why I presented an example.
did you try running the example to see how it works?
a few more examples: https://riptutorial.com/tkinter/example/22131/arranging-the-window-stack--the--lift-method-
https://riptutorial.com/tkinter/example/22131/arranging-the-window-stack--the--lift-method-

If windows occupy the same space, only lift is needed, as the lifted window will block the one underneath.

I did make it run and I understood how the option "lift" works, but I can't seem to make it work on my code. I don't know which command to put on the button in the welcome def, or if i should move this def somewhere else... I am really sorry to bother you and thanks a lot


RE: Needs help to switch frame with functions - scotesse - May-10-2020

Problem solveeddd ! I found how to make it work. Thankkss


RE: Needs help to switch frame with functions - Larz60+ - May-10-2020

It would be so much easier if you for you, if you create a class for all of your tkinter work.