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()

结果:

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM