I am trying to create a car configurator using tkinter as a gui in my free time.
I have managed to open a tkinter box with images that act as buttons.
What I want to do is for the user to click on a button. I want to check which button has been clicked (i.e if the family car button is clicked, how can I check that it has been clicked).
I have done my research on this website, and all of the solutions I have found have been in javascript or other languages.
Once the button has been clicked, I want a new window to be opened ONLY containing attributes for a family car i.e a family car can have a red exterior colour, but a sports car cannot have a red exterior colour at all.
Here is my code below:
from tkinter import * import tkinter as tk def create_window(): window = tk.Toplevel(root) root = tk.Tk() familycar = PhotoImage(file = "VW family car.png") familylabel = Button(root, image=familycar) familybutton = Button(root, image=familycar, command=create_window) familybutton.pack() So how can I check that the family car button has been clicked?
Thanks
create_window()function is called whenever thefamilybuttonhas been clicked. In that function you can do whatever you want to do when thefamilybuttonis clicked, create the window you want. Why would you need to check if it has been clicked at any other time?command=. Do keep in mind that returning values from a button press function isn't possible. Therefore, people tend to put Tkinter applications in classes, as explained in this answer.