0

i am learning python and got stuck in a place where i want to call the first function in the second function and second function into first function on clicking a button in tkinter but due to sequencing in python i am not able to do this. plz ignore the ending part after functions.

from tkinter import *
log = Tk()

log.config(bg="grey")
log.resizable(False, False)
log.title("this is gui python")
log.geometry("800x500")
log.resizable(False, False)
frame = LabelFrame(log, bg="blue", width=200, height=500, padx=0, pady=0).place(x=0, y=0)

def sign_up():
    global log
    log.config(bg="grey")
    log.resizable(False, False)
    log.title("this is gui python")
    log.geometry("800x500")
    log.resizable(False, False)
    frame = LabelFrame(log, bg="blue", width=200, height=500, padx=0, pady=0).place(x=0, y=0)
    B1 = Button(frame, text="login window", width=27, bg="violet", pady=10, command=signin_window).place(x=1, y=0)
    B2 = Button(frame, text="sign up window", width=27, bg="violet", pady=10).place(x=1, y=0)

def signin_window():
    global log
    log.config(bg="grey")
    log.resizable(False, False)
    log.title("this is gui python")
    log.geometry("800x500")
    log.resizable(False, False)
    frame = LabelFrame(log, bg="blue", width=200, height=500, padx=0, pady=0).place(x=0, y=0)
    B1 = Button(frame, text="login window", width=27, bg="violet", pady=10, relief=FLAT,).place(x=1, y=0)
    B2 = Button(frame, text="sign up window", width=27, bg="violet", pady=10, relief=FLAT, command=sign_up).place(x=1, y=50)


B1 = Button(frame, text="login window", width=27, bg="violet", relief=FLAT, pady=10, command=signin_window).place(x=1, y=0)
B2 = Button(frame, text="sign up window", width=27, bg="violet", relief=FLAT, pady=10).place(x=1, y=50)
l1 = Label(log, text="welcome to login window", font="haventica 30 bold", bg="grey").place(x=250, y=110)
l2 = Label(log, text="email", font="haventica 20", bg="grey").place(x=280, y=170)
l3 = Label(log, text="password", font="haventica 20", bg="grey").place(x=280, y=220)

e1 = Entry(log, width=40, borderwidth=3)
e1.place(x=430, y=170)

e2 = Entry(log, width=40, borderwidth=3)
e2.place(x=430, y=220)

log.mainloop()
  • Welcome to SO! I think it might benefit you to restructure your application - it may be easier to just have a separate frame for each window (sign up / log in), and a singular method for selecting those frames ([like here](https://stackoverflow.com/questions/7546050/switch-between-two-frames-in-tkinter)) - you can then set the `command` of each button to raise the other window, rather than recreating widgets each time the button is called. [This](https://stackoverflow.com/questions/17466561/best-way-to-structure-a-tkinter-application) also maybe related – Tom Jun 05 '20 at 18:44
  • thank you tom this was really helpful . hoping answers for more questions in future. – kalrav varshney Jun 06 '20 at 03:12

1 Answers1

1

in this part in the sign_up() function you did this:

    B1 = Button(frame, text="login window", width=27, bg="violet", pady=10, command=signin_window).place(x=1, y=0)

where you assigned the command "signin_window()" to it.

do you see? you used the command signin_window() before making it!

so just switch the 2 commands around and you are done.

hope it was helpful.

TimoMen
  • 13
  • 8