Python学习笔记(三)

作者: 赵楷行 | 来源:发表于2017-02-11 19:54 被阅读81次

    simple GUI with Tkinter

    from tkinter import *

    window=Tk()

    label=Label(window,text="welcome to python")

    button=Button(window,text="Click")

    label.pack()

    button.pack()

    #pack():

    window.mainloop()

    #mainloop() detects and processes the events, if the close message releases, the window will close.

    def processOK():

    print("OK button is clicked.")

    btOK=Button(window,text="OK",fg="red",bg="green",command=processOK)

    btOK.pack()

    window.mainloop()


    label和message的区别:

    TheMessagewidget is a variant of theLabel, designed to display multiline messages. The message widget can wrap text, and adjust its width to maintain a given aspect ratio.

    message是label的一个变体,用于将文字多行显示,并且可以指定一行文字的宽度。而label是单行显示。


    list

    numbers = []

    elements=5

    for i in range(elements):

        value=eval(input("Enter a new number: "))

        numbers.append(value)

    count=0

    for i in range(elements):

        if numbers[i]>0:

            count+=1

    list1 = list()

    list2 = list([2, 3, 4])

    list3 = list(["red", "green", "yellow"])

    list4 = list(range(3, 6))

    list5 = list("abcd")

    list2[0:2] #list2[0] ~ list[1]

    >>>list1 = [2, 3]

    >>>list2 = 3 * list1

    >>>list2

    [2, 3, 2, 3, 2, 3]

    >>>list1=[ x for x in range(5)]

    >>>list1

    [0, 1, 2, 3, 4] 

    >>>list2=[0.5 * x for x in list1]

    >>>list2

    [0.0, 0.5, 1.0, 1.5, 2.0]

    >>>list3=[x for x in list2 if x<1.5]

    >>>list3

    [0.0, 0.5, 1.0]


    append(x)

    remove(x)

    count(x) #输出x在list中出现的次数

    extend(list1) #把list1加到list后面

    index(x)

    insert(index, x) #把x插入index位置,index后面的元素后移一位

    pop() #把最后一个元素弹出

    reverse() #翻转list

    sort() #升序排序list


    相关文章

      网友评论

        本文标题:Python学习笔记(三)

        本文链接:https://www.haomeiwen.com/subject/fyqoittx.html