python的GUI编程(Tkinter库)(三)
2017-06-14 11:32
811 查看
消息(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()
结果:
点击相关操作:
继续:
继续:
相关文章推荐
- [Python]核心编程之GUI编程(Tkinter)
- Python Tkinter GUI编程入门介绍
- Stage5--Python GUI编程TKinter
- python学习笔记——Tkinter GUI编程——简介
- 关于python GUI编程(Tkinter) 创建子窗口及在窗口上用图片绘图
- python学习笔记——Tkinter GUI编程——简介
- Python GUI编程(Tkinter)
- python GUI编程(Tkinter)
- Python GUI编程--Tkinter
- Python GUI tkinter编程
- Python GUI编程(Tkinter)
- Python GUI编程(Tkinter)
- python的GUI编程之Tkinter
- 使用Tkinter做python的GUI编程
- Python -- Gui编程 -- Tkinter的使用 -- 对话框消息框
- Python Tkinter GUI编程入门介绍
- Python GUI编程(Tkinter)
- Python下用Tkinter进行GUI编程
- python GUI编程(Tkinter)
- Python -- Gui编程 -- Tkinter的使用 -- 对话框消息框