Home > Blockchain >  how do I assign a function?
how do I assign a function?

Time:08-12

I'm new to python, and I'm trying to work with “tkinter”.

The bottom line is that I need to assign a folder deletion function to the button

my code looks like this

from tkinter.ttk import LabeledScale 

import shutil

import pathlib 

master = tk.Tk()

lable = tk.Label(text ="delete this?")

lable.pack()

path = "C:\\Users\\kolba\\Desktop\\pythonpool"

def buttonClick():
    shutil.rmtree(path)

button = tk.Button(master, text ="yes!!!", ) #what to put after the comma?
 
button.pack()

master.mainloop()

how do I make the button work?

CodePudding user response:

You are looking for command

Function or method to be called when the button is clicked.

In this case

def buttonClick():
    shutil.rmtree(path)

button = tk.Button(master, text="yes!!!", command=buttonClick)

CodePudding user response:

You should pass the function after the comma:

button = tk.Button(master, text ="yes!!!", command = buttonClick)

You can read more about tk.Button here

  • Related