import tkinter as tk
class App:
def __init__(self, master):
frame = tk.Frame(master)
frame.pack(side=tk.LEFT, padx=50, pady=50)
self.hi_there = tk.Button(frame, text="打招呼", bg="black", fg="blue", command=self.say_hi)
self.hi_there.pack()
def say_hi(self):
print("让编程改变世界!")
root = tk.Tk()
app = App(root)
root.mainloop()
点击“打招呼”之后就是: