[英]how do I assign a function?
I'm new to python, and I'm trying to work with “tkinter”.我是 python 的新手,我正在尝试使用“tkinter”。
The bottom line is that I need to assign a folder deletion function to the button底线是我需要将文件夹删除 function 分配给按钮
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?如何使按钮工作?
you could add a font and you should put a command otherwise that button will be for nothing.你可以添加一个字体,你应该输入一个命令,否则该按钮将一事无成。 something 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!!!",command=buttonClick )
button.pack()
master.mainloop()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.