Python Tkinter 学习笔记(一) Hello world

#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

转载于:https://www.cnblogs.com/fudianheg/p/4622747.html

你可能感兴趣的:(python)