码迷,mamicode.com
首页 > 编程语言 > 详细

Python Tkinter 学习笔记(第一个简单窗口的创建)

时间:2015-07-05 19:53:29      阅读:135      评论:0      收藏:0      [点我收藏+]

标签:

#from Tkinter import *
"""
    需要使用小写的tkinter
"""
from tkinter import *
root = Tk()

w = Label(root,text="Hello fudianheg")
w.pack()

root.mainloop()

"""
    import的(tkinter)包含了所有的类,函数还有其它TK toolkit工作需要的东西大多数情况下,可以直接使用:
"""
    #from tkinter import *
"""
    我们首先要创建一个root窗口,这是一个普通的窗口,带有一些装饰和一个标题栏,每个程序你只能创建一个(root)
    窗口,而且它必须在其它窗口创建之前创建。
"""
    #root = Tk()
"""
    接下来,我们创建一个标签部件作为root窗口的child
"""
    #w = Label(root, text="hello fudianheg")
    #w.pack()
"""
    标签(Label)部件可以显示出一段文本或者一个图标或者一张图片,由于这个原因,我们用(text)来标识它。
    接下来,我们调用这个窗口的(pack)函数,根据字体自动调整窗口的大小
"""
    #root.mainloop()
"""
    在(mainloop)调用之前窗口不会显示
"""
    The program will stay in the event loop until we close the window.
    The event loop doesn’t only handle events from the user (such as mouse clicks and key presses) or the windowing system (such as redraw events and window configuration messages),
    it also handle operations queued by Tkinter itself. Among these operations are geometry management (queued by the pack method) and display updates.
    This also means that the application window will not appear before you enter the main loop.
"""
    

 翻译于:

  http://effbot.org/tkinterbook/tkinter-hello-tkinter.htm

Python Tkinter 学习笔记(第一个简单窗口的创建)

标签:

原文地址:http://www.cnblogs.com/fudianheg/p/4622747.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!