用python來做一個APP | python GUI 基礎(實戰)

上代碼
import tkinter as tk

class APP:
    def __init__(self, master):
        frame = tk.Frame(master)
        frame.pack(side=tk.LEFT, padx=10, pady=10)

        self.hi_there = tk.Button(frame, text="打招呼", bg="black", fg="white", command=self.say_hi)
        self.hi_there.pack()

    def say_hi(self):
        print("互聯網的廣大朋友們大家好,我是閆晉文!")

root = tk.Tk()
app = APP(root)

root.mainloop()

運行後彈出

這裏寫圖片描述

點擊打招呼按鈕後控制檯輸出

互聯網的廣大朋友們大家好,我是閆晉文!

一個簡單的pythonGUI完成了

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章