0

I'm not sure what I'm doing wrong because this works on a different code I've made but not this one here

import tkinter as tk
from PIL import ImageTk



roon= tk.Tk()

canvas1 = tk.Canvas(roon, width = 400, height = 400, bg='lightblue')
canvas1.pack(fill = "both", expand = True)

title = tk.Label(roon, text= "CSVrundown", bg="lightblue",fg="darkgreen", font=("rockwell", 30 ,'bold'))
canvas1.create_window(200, 40, window=title)

def csrd (times):
    print("why must you be this way")

entry1 = tk.Entry (roon) 
canvas1.create_window(200, 140, window=entry1)

but1 = tk.Button(text='Question 1', command=csrd(15))
canvas1.create_window(200, 100, window=but1)


roon.mainloop()

I wanna have it so the code executes when you press the button I'm very lost on what to do, I'm tired and I don't know who else to ask

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685

1 Answers1

3

The issue is that you are invoking the function, not passing it. To pass it you would set command=csrd. Of course, this only passes the function, not any arguments. You can use a lambda to create a function that then calls csrd with an argument of 15:

but1 = tk.Button(text='Question 1', command=lambda: csrd(15))
shayaan
  • 1,482
  • 1
  • 15
  • 32