1. 程式人生 > >Python中簡單的GUI--Tkinter例項分析--2

Python中簡單的GUI--Tkinter例項分析--2

廢話少說,直接從最初到後面一個一個程式碼展示最近參考文章(辛星tkinter第二版)書寫的程式碼內容

from tkinter import *

def xinlabel():
    '''2 ways to bind'''
    global xin
    s = Label(xin, text='i love you,ljy')
    s.pack()

xin = Tk()
b1 = Button(xin,text='ll', command=xinlabel)
b1.pack()

xin.mainloop()
from tkinter import *
from tkinter.ttk import *

def xinlabel(event):
    global xin
    s = Label(xin,text='i love you, ljy')
    s.pack()

xin = Tk()
b1 = Button(xin, text='hello')
b1.bind('<Button-1>', xinlabel)
b1.pack()

xin.mainloop()
from tkinter import *

xin = Tk()
b1 = Button(xin, text='ll')
b1['width'] = 20
b1['height'] = 4
b1.pack()

b2 = Button(xin, text='love you')
b2['width'] = 20
b2['background'] = 'red'
b2.pack()

xin.mainloop()