Define needs a fix

why when you define something, and start the programm, i starts with the content in the defined line?
it should be the other way around, as defined worths are not always defined at the start, it blocks the use of Tkinter, so please, make def, DEFINE and not execute

from tkinter import *
import time

check = “”

def confirm():
check = text.get()
if check == (“print(“Hallo Welt”)”):
Congrats = Label(practice, text=“Bravo, aufgabe erledigt”).grid(row=3, column=1)
Congrats = Label(practice, text=“Falsch”).grid(row=3, column=1)

instruction = Tk()
practice = Tk()

Tutorial = Label(instruction, text=“Print function gibt ein text hinaus\ndiese wird: \nprint(“Hello world”)\ngeschrieben”).pack()
user = Label(practice, text=“mach dass python “Hallo Welt” sagt :”).grid(row=1, column=1)
text = Entry(practice).grid(row=1, column=2)

click = Button(practice, text=“Nachschauen”, command=confirm()).grid(row=2, column=1)


This means that Congrats will be the returned value of the grid function which is None.

Do not do this. A Tk is a mainwindow with (a part of) the application. Having two of those in your application can be done, but it needs a lot of experience. See Toplevel for a second non-modal window.

I think the next thing is what the original post is about:

What you do here, is assigning the returned value of confirm() to the command parameter. That is not what you want, remove the parenthesis after confirm, so that when click is clicked, it will execute confirm(). Functions are first class objects in Python, so you can pass them as parameters, but without the parenthesis.

B.t.w., next time please format your code by using the blockquote icon in the editor. It makes it so much easier to read it and errors may be obscured if you don’t.