有人可以解释一下如何使用 python 3 在两个函数之间传递变量吗?
can someone please explain me how to pass variables between 2 functions using python 3?
我试图在两个函数之间传递一个变量,但我不明白我哪里错了,因为它不起作用。
这是我的 python3 脚本:
from tkinter import *
w1=Tk()
w2=Tk()
def go(which):
print(which)
b=Button(w2,text='print',command=lambda:go(which.get()))
b.pack()
w2.withdraw()
def main(which):
w2.deiconify()
b1=Button(w1,text='button 1',command=lambda:main('button 1'))
b1.pack()
b2=Button(w1,text='button 2',command=lambda:main('button 2'))
b2.pack()
w1.mainloop()
谢谢
好吧我自己解决了:
from tkinter import *
w1=Tk()
w2=Tk()
w2.withdraw()
def main(which):
w2.deiconify()
def go(which):
print(which)
b=Button(w2,text='print',command=lambda:go(which))
b.pack()
b1=Button(w1,text='button 1',command=lambda:main('button 1'))
b1.pack()
b2=Button(w1,text='button 2',command=lambda:main('button 2'))
b2.pack()
w1.mainloop()
我试图在两个函数之间传递一个变量,但我不明白我哪里错了,因为它不起作用。 这是我的 python3 脚本:
from tkinter import *
w1=Tk()
w2=Tk()
def go(which):
print(which)
b=Button(w2,text='print',command=lambda:go(which.get()))
b.pack()
w2.withdraw()
def main(which):
w2.deiconify()
b1=Button(w1,text='button 1',command=lambda:main('button 1'))
b1.pack()
b2=Button(w1,text='button 2',command=lambda:main('button 2'))
b2.pack()
w1.mainloop()
谢谢
好吧我自己解决了:
from tkinter import *
w1=Tk()
w2=Tk()
w2.withdraw()
def main(which):
w2.deiconify()
def go(which):
print(which)
b=Button(w2,text='print',command=lambda:go(which))
b.pack()
b1=Button(w1,text='button 1',command=lambda:main('button 1'))
b1.pack()
b2=Button(w1,text='button 2',command=lambda:main('button 2'))
b2.pack()
w1.mainloop()