简体   繁体   English

在 python 中互相调用函数

[英]calling functions in one another in python

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.我正在学习 python 并卡在一个地方我想调用第一个 function 到第二个 function 和第二个 function 到第一个 function 点击 tkinter 中的一个按钮,但由于 i4573 无法在 884 中执行 454 do 482 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()

in this part in the sign_up() function you did this:在 sign_up() function 的这一部分中,您执行了以下操作:

    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.您将命令“signin_window()”分配给它的位置。

do you see?你有看到? you used the command signin_window() before making it!你在制作它之前使用了命令 signin_window() !

so just switch the 2 commands around and you are done.所以只需切换 2 个命令即可完成。

hope it was helpful.希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM