button.bind不调用函数tkinter

时间:2019-04-02 21:00:03

标签: python tkinter

单击按钮将调用打印到控制台的相应功能。 (目前,打印只是一个占位符)-我现在正在尝试该功能。预先感谢

from tkinter import *

root = Tk()

def load_json_button(event):
    print("Load JSON")

def save_json_button():
    print("Save JSON")

def select_property_button():
    print("Select Property")

def save_property_button():
    print("Save Property")

top_frame = Frame(root, width=450, height=300)
top_frame.pack()

button1 = Button(top_frame, text="Load JSON",fg="blue")
button1.bind("<Button-1>", load_json_button)
button1.pack(side=LEFT)

button2 = Button(top_frame, text="Save JSON", fg="green")
button2.bind("<Button-1>", save_json_button)
button2.pack(side=RIGHT)

button3 = Button(top_frame, text="Select Property", fg="purple")
button3.bind("<Button-1>", select_property_button)
button3.pack(side=RIGHT)

button4 = Button(top_frame, text="Save Property", fg="black")
button4.bind("<Button-1>", save_property_button)
button4.pack(side=RIGHT)

root.mainloop()

0 个答案:

没有答案