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