Discuss / Python / 窗口与控制台的示例

窗口与控制台的示例

Topic source

ywjco_567

#1 Created at ... [Delete] [Delete and Lock User]

想当年VB6下面用鼠标画窗口、画按钮、画文本框,只需要自己写事件的Sub,在模块里写公共Function。原来这么一个当年的菜鸟玩的东西,在这里这么复杂。

# !/usr/bin/python3
# -*-coding:UTF-8-*-

import tkinter as tk

class Application(tk.Frame):
    def __init__(self, master=None):
        super().__init__(master)
        self.master = master
        self.pack()
        self.create_widgets()

    def create_widgets(self):
        self.hi_there = tk.Button(self)
        self.hi_there["text"] = "Hello World\n(click me)"
        self.hi_there["command"] = self.say_hi
        self.hi_there.pack(side="top")

        self.quit = tk.Button(self, text="QUIT", fg="red", command=self.master.destroy)
        self.quit.pack(side="bottom")

    def say_hi(self):
        print("hi there, everyone!")

def main():
    root = tk.Tk()
    app = Application(master=root)
    app.master.title('Hello World')    # 设置窗口标题
    app.mainloop()    # 主消息循环


if __name__ == '__main__':
    main()

好道者

#2 Created at ... [Delete] [Delete and Lock User]

是啊,而且老师也说了,如果要编写复杂的GUI界面还是用操作系统原生的语言,看来python并不善于GUI


  • 1

Reply