0

I solved the problem I asked for in Put a Label in a function-generated window from another function

Now, I have another problem on the same script.

def window1():
    windowone=Tk()
    button1=button(windowone, command=window2)

def put():
    labeltoput=label(windowtwo, text"text to put")

def window2():
    windowtwo=Tk()
    putlabel=button(windowtwo, text="put label on windowone", command=put)

Now, when I click on the Button putlabel, I want that the label in the function put goes in the windowtwo, instead of appearing in the windowone.

They're all global variables.

nbro
  • 15,395
  • 32
  • 113
  • 196
HANZO
  • 55
  • 1
  • 1
  • 8

1 Answers1

2

You can't call Tk() twice in the same program1. If you want a window, create an instance of Toplevel.

1Technically you can, but only when you understand the ramifications. Unless you have a fairly deep understanding of Tkinter, it almost certainly won't behave like you expect it to.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
  • windowtwo is garbage collected when the function window2() exits. I would strongly suggest learning classes before Tkinter. Then you can make windowtwo an instance variable that can been used throughout the class. And note that you should use windowtwo=Toplevel(windowone) to avoid possible conflicts. –  Mar 05 '15 at 19:08
  • Example for global variables http://effbot.org/pyfaq/how-do-you-set-a-global-variable-in-a-function.htm –  Mar 05 '15 at 19:17