0

I am trying to display some text after a button is pressed but all I seem to be able to do make it so that text is displayed before the button is pressed or not at all. here is my code so far:

import tkinter

def label1():
    label2 = tkinter.Label(window1, text = "correct")
    label.pack()

def Window2():
    window1 = tkinter.Tk()
    window1.title("start")
    label = tkinter.Label(window1, text= "how do you spell this Sh--ld")
    label.pack()
    points = 0
    i = points + 1
    button = tkinter.Button(window1, text = "ou", command = label1)
    button.pack()



window = tkinter.Tk()
window.title("menu")

button = tkinter.Button(window, text = "start", command = Window2)
button.pack()

I am trying to get the button in the Window2 subroutine to display the text

1
  • 1
    First of all, you should not use multiple Tk() instances. Change tkinter.Tk() to tkinter.Toplevel() inside Window2(). Commented Feb 8, 2020 at 16:17

1 Answer 1

1

Here is how you can do it

import tkinter

def label1(root):
    label = tkinter.Label(root, text = "correct")
    label.pack()

def Window2():
    window1 = tkinter.Tk()
    window1.title("start")
    label = tkinter.Label(window1, text= "how do you spell this Sh--ld")
    label.pack()
    points = 0
    i = points + 1
    button = tkinter.Button(window1, text = "ou", command = lambda root = window1: label1(root))
    button.pack()



window = tkinter.Tk()
window.title("menu")

button = tkinter.Button(window, text = "start", command = Window2)
button.pack()

window.mainloop()
Sign up to request clarification or add additional context in comments.

3 Comments

Can you explain the solution, and why you left the multiple instances of Tk()?
I don't know where is the problem in lefting multiple tkinter loops running, i'm not an expert in tkinter, he asked for help and i gave it to him , if you think that there is a better solution just write it :)
I don't know where is the problem in lefting multiple tkinter loops running, i'm not an expert in tkinter Neither am I, I was just sharing advice that seems decently common on here. See, for example: stackoverflow.com/questions/48045401/…. if you think that there is a better solution just write it :) I disagree, and I'm not a fan of that attitude, I think it's how we end up with ancient questions whose accepted answer is highly upvoted despite being wrong, as the other, far superior ones, remain unseen by the majority of people.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.