Python3 tkinter模块 学习笔记 自带例子分析详解(二)

Python3 tkinter模块 学习笔记(二)

一个 tkinter 中自带的例子

 Example (Hello, World):
    import tkinter 
    from tkinter.constants import *
    tk = tkinter.Tk()
    frame = tkinter.Frame(tk, relief=RIDGE, borderwidth=2)
    frame.pack(fill=BOTH,expand=1)
    label = tkinter.Label(frame, text="Hello, World")
    label.pack(fill=X, expand=1)
    button = tkinter.Button(frame,text="Exit",command=tk.destroy)
    button.pack(side=BOTTOM)
    tk.mainloop()

运行结果:

Python3 tkinter模块 学习笔记 自带例子分析详解(二)_第1张图片 看上去还是可以的(一行字 + 一个写着Exit的Button控件),自带的例子简单的实现了一个窗口

分析一下:
1.import 引入 tkinter 模块

2.from *** import *** 引入tkinter的全部的常量(大概)

>>> help(tkinter.constants)
Help on module tkinter.constants in tkinter:

NAME
    tkinter.constants - # Symbolic constants for Tk

DATA
    ACTIVE = 'active'
    ALL = 'all'
    ANCHOR = 'anchor'
    ARC = 'arc'
    BASELINE = 'baseline'
    BEVEL = 'bevel'
    BOTH = 'both'
    BOTTOM = 'bottom'
    BROWSE = 'browse'
    BUTT = 'butt'
    CASCADE = 'cascade'
    CENTER = 'center'
    CHAR = 'char'
    CHECKBUTTON = 'checkbutton'
    CHORD = 'chord'
    COMMAND = 'command'
    CURRENT = 'current'
    DISABLED = 'disabled'
    DOTBOX = 'dotbox'
    E = 'e'
    END = 'end'
    EW = 'ew'
    EXTENDED = 'extended'
    FALSE = 0
    FIRST = 'first'
    FLAT = 'flat'
    GROOVE = 'groove'
    HIDDEN = 'hidden'
    HORIZONTAL = 'horizontal'
    INSERT = 'insert'
    INSIDE = 'inside'
    LAST = 'last'
    LEFT = 'left'
    MITER = 'miter'
    MOVETO = 'moveto'
    MULTIPLE = 'multiple'
    N = 'n'
    NE = 'ne'
    NO = 0
    NONE = 'none'
    NORMAL = 'normal'
    NS = 'ns'
    NSEW = 'nsew'
    NUMERIC = 'numeric'
    NW = 'nw'
    OFF = 0
    ON = 1
    OUTSIDE = 'outside'
    PAGES = 'pages'
    PIESLICE = 'pieslice'
    PROJECTING = 'projecting'
    RADIOBUTTON = 'radiobutton'
    RAISED = 'raised'
    RIDGE = 'ridge'
    RIGHT = 'right'
    ROUND = 'round'
    S = 's'
    SCROLL = 'scroll'
    SE = 'se'
    SEL = 'sel'
    SEL_FIRST = 'sel.first'
    SEL_LAST = 'sel.last'
    SEPARATOR = 'separator'
    SINGLE = 'single'
    SOLID = 'solid'
    SUNKEN = 'sunken'
    SW = 'sw'
    TOP = 'top'
    TRUE = 1
    UNDERLINE = 'underline'
    UNITS = 'units'
    VERTICAL = 'vertical'
    W = 'w'
    WORD = 'word'
    X = 'x'
    Y = 'y'
    YES = 1

import tkinter
from tkinter.constants import *
tk = tkinter.Tk()                                               #tk实例化(一般是 root = TK())

frame = tkinter.Frame(tk, relief=RIDGE, borderwidth=2)
                                                                                            #实例化一个frame对象,并放在tk上,浮雕模式为RIDGE,边界宽度 = 2
frame.pack(fill=BOTH,expand=1)
                                                                            #把frame对象显示在显示器上,充满整个容器,expand扩充(具体我忘了
label = tkinter.Label(frame, text="Hello, World")
                                                                            #实例化一个label标签对象,并放在frame上,上面写“Hello,World”
label.pack(fill=X, expand=1)
                                                              #把label对象显示在显示器上,X轴方向填
button = tkinter.Button(frame,text="Exit",command=tk.destroy)
                                                                            #实例化一个button标签对象,并放在fame上,上面写“”Exit“”,点击按钮是调用函数tk.destroy
                                                                        #这里要注意调用的函数不能加括号,加上的话会报错的,因为程序会直接调用函数,而不是点击后调用,会出错。
button.pack(side=BOTTOM)
                                             #把button对象显示在显示器上,放到底部显示
tk.mainloop()
                                #把上述控件不断循环显示+提供功能

差不多就有一些像样的窗口了 不得不说tkinter模块写出来的窗口贼丑,而且很多功能找也找不到。

希望有看到的童鞋帮我解决一下:

如何用tkinter绘制不规则窗口?

反正我是找了很多博文都没有类似让我满意的解答,交给你们了亲!

你可能感兴趣的:(Python,tkinter,随便写写,不规则窗口改怎么搞)