from tkinter import ×
from tkinter import ttk
root=Tk()
button=ttk.Button(root,text="Click Me") #新建一个button项目,其中text内容显示为click me
button.pack() #排版
def callback(): #定义一个callback函数。会打印“Clicked”
print("Clicked")
button.config(command=callback) #当点击button 就会召唤callback函数
button.invoke() #invoke是祈求的意思。视频说的是模拟按键,本次返回一个Clicked(相当于手动click)
button.state([‘disabled‘]) #设置状态为disable。 就没法按button按钮了
button.instate([‘disabled‘]) #查看button状态是否是disabled,
button.state([‘!disabled‘]) #设置取消disabled
small_log=logo.subsample(5,5) #缩小图片 每五个值取一个?
button.config(image=small_log)
root.mainloop()
According to the docs,
subsample(self, x, y=‘‘)
Return a new PhotoImage based on the same image as this widget but use only every Xth or Yth pixel.
I.e. subsample
doesn‘t modify the image, it creates a new one, so try this instead:
originalPlantImage = PhotoImage(file="images/Arable_Cell.gif")
displayPlantImage = originalPlantImage.subsample(2, 2)
canvas.create_image(0, 0, anchor=NW, image=displayPlantImage)