zoukankan      html  css  js  c++  java
  • 折腾Python中的Tkinter

    折腾Python中的Tkinter

    从oschina看到了关于Python的Tkinter简介:

    Tk图形用户界面 Tkinter

    又从Python官网文档:

    Tkinter — Python interface to Tcl/Tk

    中,知道了Tkinter是Python内置的。

    打算去折腾试试。


    1.参考官网的代码,写了下面的:

    #!/usr/bin/python
    # -*- coding: utf-8 -*-
    """
    -------------------------------------------------------------------------------
    Function:
    【记录】折腾Python中的Tkinter
    http://www.crifan.com/try_python_tkinter_module
    
    Author:     Crifan
    Verison:    2012-11-30
    -------------------------------------------------------------------------------
    """
    
    from Tkinter import *;
    
    class Application(Frame):
        def say_hi(self):
            print "hi there, everyone!"
    
        def createWidgets(self):
            self.QUIT = Button(self)
            self.QUIT["text"] = "QUIT"
            self.QUIT["fg"]   = "red"
            self.QUIT["command"] =  self.quit
    
            self.QUIT.pack({"side": "left"})
    
            self.hi_there = Button(self)
            self.hi_there["text"] = "Hello",
            self.hi_there["command"] = self.say_hi
    
            self.hi_there.pack({"side": "left"})
    
        def __init__(self, master=None):
            Frame.__init__(self, master)
            self.pack()
            self.createWidgets()
    
    def tkinterDemo():
        root = Tk()
        app = Application(master=root)
        app.mainloop()
        root.destroy()
    
        
    ###############################################################################
    if __name__=="__main__":
        tkinterDemo();

    然后去cmd中运行,可以看到有对应的图形界面显示出来了:

    show gui

    然后点击Hello,也可以在cmd中显示出对应的信息:

    click hello show hello

    还是有点意思的。

    【总结】

    算是内置的图形库,有空可以好好折腾折腾。

  • 相关阅读:
    VBA键码常数
    枚举
    海龟交易法则及头寸
    HQL.TOP
    jquery.cookie
    机械操作产品分析.
    Repeater排序2
    Repeater排序
    json
    LoginStatus注销控件
  • 原文地址:https://www.cnblogs.com/timssd/p/5545466.html
Copyright © 2011-2022 走看看