Ishita
Ishita

Reputation: 15

Trying to get a GUI but nothing comes up, no GUI, and no errors on command window

import tkinter as tk
window = tk.Tk()
window.title("WORD GAME")
def game():
    print("Hi window !")

heading_label1 = tk.Label(window, text="WANNA PLAY THE GAME ?? ....")
heading_label1.pack()
button1 = tk.Button(window, text="YES", command=lambda: game())
button1.pack()
button2 = tk.Button(window, text="NO", command=exit())
button2.pack()

window.mainloop()

Nothing is being shown in the output neither any error nor window.

Upvotes: 0

Views: 28

Answers (1)

figbeam
figbeam

Reputation: 7176

The line:

button2 = tk.Button(window, text="NO", command=exit())

actually runs the exit command as you end exit() with parenthesis.

To assign a command to a button you just supply the name:

button2 = tk.Button(window, text="NO", command=exit)

Upvotes: 1

Related Questions