python的GUI编程(Tkinter库)(三)

消息(message)

消息控件提供了显示多行文本的方法,且可以设置字体和背景颜色
示例:

from Tkinter import *
root=Tk()
root.title('top')
Message(root,text='you can record your wonderful thing ,you can record your wonderful thing ',\
        bg='blue',fg='ivory',relief=GROOVE).pack(padx=10,pady=10)
root.mainloop()

结果:
这里写图片描述

列表(ListBox)

列表框组件是一个选项列表,用户可以从中选择某一选项
示例:

from Tkinter import *
root=Tk()
root.title()
l=Listbox(root,width=15)
l.pack()
for item in ['apple','orange','peach','banana','melon']:
    l.insert(END,item)
root.mainloop()

结果:
这里写图片描述

滚动条(Scrollbar)

滚动条组件可以添加至任何一个组件,一些组件在界面显示不下时会自动添加滚动条,但是可以使用滚动条组件来对其进行控制
示例:

from Tkinter import *
root=Tk()
root.title('top')
l=Listbox(root,height=6,width=15)
scroll=Scrollbar(root,command=l.yview)
l.configure(yscrollcommand=scroll.set)
l.pack(side=LEFT)
scroll.pack(side=RIGHT,fill=Y)
for item in range(20):
    l.insert(END,item)
root.mainloop()

结果:
这里写图片描述

消息框(messagebox)

消息窗口用于弹出提示框像用户进行警告,或让用户选择选择下一步如何操作,消息框包括很多类型,长用的有info、warning、error、yesno、OKcancel等,包含不同的的图标、按钮以及弹出提示音。
示例:

import Tkinter as tk
import tkMessageBox as msgbox
def btn1_clicked():
    msgbox.showinfo("info","showinfo test.")
def btn2_clicked():
    msgbox.showwarning("warning","showwarning test.")
def btn3_clicked():
    msgbox.showerror("error","showerror test.")
def btn4_clicked():
    msgbox.askquestion("question","askquestion test.")
def btn5_clicked():
    msgbox.askyesno("yesno","askyesno test.")
def btn6_clicked():
    msgbox.askokcancel("okcancel","askcancel test.")
def btn7_clicked():
    msgbox.askretrycancel("retry","askretrycancel test.")
root=tk.Tk()
root.title("Msgbox test")
btn1=tk.Button(root,text="showinfo",command=btn1_clicked)
btn1.pack(fill=tk.X)
btn2=tk.Button(root,text="showwarning",command=btn2_clicked)
btn2.pack(fill=tk.X)
btn3=tk.Button(root,text="showerror",command=btn3_clicked)
btn3.pack(fill=tk.X)
btn4=tk.Button(root,text="showaskquestion",command=btn4_clicked)
btn4.pack(fill=tk.X)
btn5=tk.Button(root,text="askyesno",command=btn5_clicked)
btn5.pack(fill=tk.X)
btn6=tk.Button(root,text="showokcancel",command=btn6_clicked)
btn6.pack(fill=tk.X)
btn7=tk.Button(root,text="showretrycancel",command=btn7_clicked)
btn7.pack(fill=tk.X)
root.mainloop()

结果:
这里写图片描述
点击相关操作:
这里写图片描述
继续:
这里写图片描述
继续:
这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值