python Tkinter基础 Button command在窗体中添加一个按钮,单击按钮 在IDLE中打印一行字

code 

# Tkinter基础 Button command在窗体中添加一个按钮,单击按钮 在IDLE中打印一行字

import tkinter as tk

class App():
    def __init__(self, master):
        frame = tk.Frame(master)
        frame.pack()

        self.testButton = tk.Button(frame, text = "hello", fg = "blue", command = self.testPrint)
        self.testButton.pack()

    def testPrint(self):
        print("测试消息!!!!")


root = tk.Tk()
app = App(root)
root.mainloop()

结果:

 

posted @ 2018-01-24 19:57  吴威振  阅读(2711)  评论(0)    收藏  举报