Python Forum
[Tkinter] Needs help to switch frame with functions
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Needs help to switch frame with functions
#1
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()
Reply
#2
you can do this using tkinter lift and lower. see: https://python-forum.io/Thread-Tkinter-C...#pid111150
Reply
#3
(May-09-2020, 10:44 PM)Larz60+ Wrote: you can do this using tkinter lift and lower. see: https://python-forum.io/Thread-Tkinter-C...#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...
Reply
#4
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/...ift-method-
https://riptutorial.com/tkinter/example/...ift-method-

If windows occupy the same space, only lift is needed, as the lifted window will block the one underneath.
Reply
#5
(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/...ift-method-
https://riptutorial.com/tkinter/example/...ift-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
Reply
#6
Problem solveeddd ! I found how to make it work. Thankkss
Reply
#7
It would be so much easier if you for you, if you create a class for all of your tkinter work.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Scrollbar, Frame and size of Frame Maksim 2 5,023 Sep-30-2019, 07:30 AM
Last Post: Maksim
  [Tkinter] create and insert a new frame on top of another frame atlass218 4 5,675 Apr-18-2019, 05:36 PM
Last Post: atlass218
  [Tkinter] Frame size only works if frame is empty(Solved) Tuck12173 7 3,437 Jan-29-2018, 10:44 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020