第19章 图形用户界面编程(2)

19.3 Tkinter举例

19.3.1 标签组件

import Tkinter
top = Tkinter.Tk()

label = Tkinter.Label(top, text = 'Hello World!')
label.pack()
Tkinter.mainloop()

label.pack()指明用packer来管理和显示组件。

19.3.2 按钮组件

import Tkinter
top = Tkinter.Tk()

quit = Tkinter.Button(top, text = 'Hello World!', command = top.quit)
quit.pack()
Tkinter.mainloop()
按钮回调top.quit,让整个程序退出。

19.3.3 标签和按钮组件

import Tkinter
top = Tkinter.Tk()

hello = Tkinter.Label(top, text = 'Hello World!')
hello.pack()

quit = Tkinter.Button(top, text = 'QUIT', command = top.quit, bg = 'red', fg = 'white')
quit.pack(fill = Tkinter.X, expand = 1)
Tkinter.mainloop()
19.3.4 标签、按钮和进度条组件

from Tkinter import *

def resize(ev = None):
    label.config(font = 'Helvetica -%d bold' % scale.get())

top = Tk()

hello = Label(top, text = 'Hello World!', font = 'Helvetica -12 bold')
hello.pack(fill = Y, expand = 1)

scale = Scale(top, from_ = 10, to = 40, orient = HORIZONTAL, command = resize)
scale.set(12)
scale.pack(fill = X, expand = 1)

quit = Button(top, text = 'QUIT', command = top.quit, bg = 'red', fg = 'white')
quit.pack()

mainloop()


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值