0

so I have a tkinter window with a play button

import tkinter
from play_function import *

window = tkinter.Tk()
screen_width = window.winfo_screenwidth()
screen_height = window.winfo_screenheight()
window.config ( width = screen_width )
window.config ( height = screen_height )
window.config ( background = "black" )
title = tkinter.Label ( window , text = "Scrabble" , background = "black" , foreground = "green" , font = ( "Comic Sans MS" , 200 ) )
title.pack()
play_button = tkinter.Button ( window , text = "PLAY" , background = "blue" , foreground = "black" , font = ( "Comic Sans MS" , 80 ) )
exit_button = tkinter.Button ( window , text = "EXIT" , background = "red" , foreground = "black" , font = ( "Comic Sans MS" , 77 ) , command = window.destroy )
play_button.config ( command= play ( title , play_button , exit_button ) )
space = tkinter.Label ( foreground = "black" , background = "black" , height = 2 , width = 50 )

play_button.pack()
space.pack()
exit_button.pack()



window.mainloop()

and I've made a separate file with a function for that button

import tkinter
def play (title , button_1 , button_2) :
    title.destroy()
    button_1.destroy()
    button_2.destroy()

but because I need to give it some variables I open the parentheses and it calls the function play_button.config ( command= play ( title , play_button , exit_button ) ) how can I fix this ?

what it does with my code is that it calls the function and destroy my buttons but what I would like it to do is only destroy the objects when I press the button

  • Please try to use correct upper case letters, e.g. in the beginning of your title, sentences or the word "I". This would be gentle to your readers. – buhtz Feb 23 '23 at 09:29

1 Answers1

0

I think the simple solution to your problem is lambda. What you would do is yourbutton = tkinter.Button(command=lambda:yourfunction().

Just a simple example: from tkinter import *

root = Tk()


def test(text):
    print(text)


B1 = Button(root, command=lambda:test("one"))
B1.pack()

root.mainloop()

I hope this solves your problem.

A J
  • 96
  • 5