0

i'm trying to pass one variable between 2 functions, but i don't understand where i'm wrong, because it doesn't work. here's my python3 script:

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()

thanks

Tommy
  • 101
  • 8
  • See [Why are multiple instances of Tk discouraged](https://stackoverflow.com/questions/48045401/why-are-multiple-instances-of-tk-discouraged) – Bryan Oakley Feb 01 '22 at 18:41

1 Answers1

0

ok i just solved by myself:

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()
Tommy
  • 101
  • 8