用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完成了

猜你喜欢

转载自blog.csdn.net/qq_30262201/article/details/78939092
今日推荐